I am working with a recursive function like:
from functools import lru_cache
init = {0:1,1:1}
@lru_cache(maxsize=10000)
def fib(n):
global init
if n in init.keys():
return init[n]
else:
return fib(n-1)+fib(n-2)
and I defined init as a global variable in order to save all the mid steps for any future computation, but if I run:
print(fib(20))
print(init)
It prints:
10946
{0: 1, 1: 1}
Why even when I defined init as a global variable it still prints the same dictionary? I bet that it is because of the return statement but I might be worng.