Section: Itertools and functools

LRU cache

python
python
from functools import lru_cache

@lru_cache(maxsize=128)
def fib(n: int) -> int:
    return n if n < 2 else fib(n - 1) + fib(n - 2)

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Itertools and functools
Chain iterables
Chain iterables
OpenIn sheetpythonsame section
Group consecutive items
Group consecutive items
OpenIn sheetpythonsame section
Cartesian product
Cartesian product
OpenIn sheetpythonsame section
Accumulate totals
Accumulate totals
OpenIn sheetpythonsame section
Parse JSON
Parse JSON
Regex search
Regex search