cache
def fact(): arr = {} def fact_in(n): if n not in arr.keys(): if n == 0: res = 1 else: res = n * fact_in(n-1) arr[n] = res print(n, res) return arr[n] return fact_in fact_calc = fact() print(fact_calc(10)) print(fact_calc(9))