Skip to main content Brad's PyNotes

Posts on Functional-Programming

  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!

  2. Itertools Module: Iterator Building Blocks for Efficient Loops

    TL;DR

    The itertools module provides memory-efficient iterator building blocks like chain(), combinations(), cycle(), and count() for creating powerful iteration patterns.

    Interesting!

    The itertools.product() function can generate Cartesian products infinitely - perfect for nested loops without the nesting complexity.