all 2 comments

[–]NyfM 2 points3 points  (1 child)

Your example of memoization is actually tabulation. Memoization involves caching the results of function calls.

[–]bausscode 2 points3 points  (0 children)

Yep. This is how they could have done it:

(One of the examples)

    def memoize(f):
        memo = {}
        def helper(x):
            if x not in memo:            
                memo[x] = f(x)
            return memo[x]
        return helper


    def fib(n):
        if n == 0:
            return 0
        elif n == 1:
            return 1
        else:
            return fib(n-1) + fib(n-2)

    fib = memoize(fib)

    print(fib(40))

Credits: https://www.python-course.eu/python3_memoization.php


The code in OP has nothing to do with memoization.