look_up = {(0): 1}

def fact(n):
    if n not in look_up:
        print('recursing when n is {}'.format(n))
look_up[n] = n * fact(n - 1)
return look_up[n]
fact(3)
fact(4)
fact(4)
Recursive factorial using dict causes RecursionError