Skip to main content Brad's PyNotes

Posts on Functools

  1. Functools Module: Higher-Order Functions and Functional Programming

    TL;DR

    The functools module provides utilities for functional programming including partial(), lru_cache(), singledispatch(), and reduce() for creating reusable, optimized higher-order functions.

    Interesting!

    The @lru_cache decorator can dramatically speed up recursive functions like Fibonacci calculations by memoizing results - turning an O(2^n) algorithm into O(n) with just one line!