functools is a standard library in Python, offering utility for functional programming.
Use lru_cache to memoize function calls:
from functools import lru_cache
@lru_cache(maxsize=None)
def fib(n):
if n < 2:
return n
return fib(n-1) + fib(n-2)
Resources
For docs, see: https://docs.python.org/3/library/functools.html