human
I am working on the file ".ipynb_checkpoints/memoize-checkpoint.ipynb".
The first task is:
Using the .setdefault() method instead of the .get() method looks better, but suffers the same flaw of defeating the memoization by always calling f(x).
Can you write Python code for it?

=====
Can you provide a the Python code you requested?
assistant
#Here is the Python code you requested.

def memoize(f):
    results = {}
    def helper(x):
        return results.setdefault(x, f(x))
    return helper

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

%timeit fib(n)
fib(n)