Recursive Fibonacci generator
As pointed out, top-down recursive approaches are almost never a good idea when it comes to Fibonacci numbers. Consider the alternative iterative approach:

def fib(n):
    while n &lt;= len(fib.cache):
        fib.cache.append(fib.cache[-1] + fib.cache[-2])
    return fib.cache[n]
fib.cache = [0, 1]


Notice how the memoization cache is stored as an attribute of the function, which is the closest thing in Python to having a static variable inside a function.