Hello!
I use this decorator for memoization. But how i can check if results number is really cached?
When i try to print fib.cache or cache[n] i got error: cache is not defined.
How can i print cache dictionary and check if it's really working?
I use this decorator for memoization. But how i can check if results number is really cached?
When i try to print fib.cache or cache[n] i got error: cache is not defined.
How can i print cache dictionary and check if it's really working?
def memoize(f): cache = {} def decorate(*args): if args not in cache: cache[args] = f(*args) return cache[args] return decorate @memoize def fib(n): assert n >=0 if n < 2: return n else: return fib(n-1) + fib(n-2)Thank you!