Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cache = dict()
- def memoize(func):
- def wrapper(*args, **kwargs):
- if (args, frozenset(kwargs.items())) not in cache:
- #print("If I uncomment this then CALLING f 2 is printed, otherwise not")
- cache[(args, frozenset(kwargs.items()))] = func(*args, **kwargs)
- return cache[(args, frozenset(kwargs.items()))]
- return wrapper
- @memoize
- def f(x):
- print("CALLING: f {}".format(x))
- return x ** 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement