Skip to main content

← All terms · Standard library

functools.cache

Memoize a pure function with `@functools.cache`. Replaces hand-rolled dict caching.

Learn this interactively:

Open lesson lesson-131

Related — Standard library

pathlib.PathObject-oriented filesystem paths. `Path(".").rglob("*.py")` beats `os.walk + os.collections.CounterDict subclass that counts hashable items: `Counter("hello")` → `{'l': 2, ...}`.itertoolsIterator building blocks — `chain`, `groupby`, `combinations`, `accumulate`. Lazdataclasses.fieldConfigure a dataclass attribute — mutable defaults, init/repr behavior. Use `fiecollections.defaultdictDict that auto-creates missing keys with a factory: `defaultdict(list)` returns