Python, Data Science, Artificial Intelligence, Programming, Tips.
inputs occur again. This can help avoid redundant computations. Python provides the functools.lru_cache decorator for easy memoization: from functools import lru_cache @lru_cache(maxsize=None) def fibonacci(n): if n < 2: return n return fibonacci(n-1) + fibonacci(n-2) The @lru_cache decorator