functools
Tools for functions: lru_cache, cache, partial, reduce, wraps, singledispatch, total_ordering, cached_property.
Intermediate
from functools import lru_cache, partial
@lru_cache(maxsize=None)
def fib(n): return n if n < 2 else fib(n - 1) + fib(n - 2)
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.