I would like to understand memoization in Python better. In an online class I am taking, the following example is provided:
def memoize(func):
memo_dict = {}
def wrapper(*args):
if args not in memo_dict:
memo_dict[args] = func(*args)
return memo_dict[args]
return wrapper
@memoize
def find_divisors_memo(n):
divisors = []
for i in range(1, n+1):
if n % i == 0:
divisors.append(i)
return divisors
I am trying to find the numerical values stored in memo_dict
after running a few examples, e.g.:
find_divisors_memo(100000009)
find_divisors_memo(100000008)
I do:
for x,y in memo_dict.items():
print(x,y)
and it says: NameError: name 'memo_dict' is not defined
.