I am having trouble understanding the following code although I tried it on pythontutor.
def fastFib(n, memo = {}):
if n == 0 or n == 1:
return 1
try:
return memo[n]
except KeyError:
result = fastFib(n-1, memo) + fastFib(n-2, memo)
memo[n] = result
return result
My question is how come memo is not empty whenever it calls fastFib? When I tried it in pythontutor, there is only one memo and updated with new information. I thought that as fastFib(n, memo ={}) already specify the memo is empty, memo should be empty whenever it enters fastFib. What do I miss here?
Basically I think I am totally lost in this code. I really appreciate if you help me out understand this code.
Thank you.