Python โ From Basics to Advanced ยท Standard Library
functools โ cache, reduce, partial
Standard Library
Introduction
functools provides tools for functional programming and decorators. @cache and @lru_cache memoize results (hashable keys). reduce collapses an iterable into one value. partial creates "pre-configured" functions. @wraps preserves metadata in decorators. @singledispatch dispatches on the first argument's type. @cached_property is a property computed once per instance. @total_ordering generates all comparison operators from __eq__ + __lt__.