Loading video player…

Python itertools By Example (Overview)

The narration in this course is an AI-generated clone of Stephen Gruppetta’s voice, used with Stephen’s consent.

Python’s itertools module is one of the hidden gems of the standard library. Knowing the definitions of its functions isn’t enough, though. Its real power lies in composing those functions into fast, memory-efficient, and readable code.

Rather than introducing itertools one function at a time, this video course works through practical examples that encourage you to think iteratively: you’ll shuffle and deal a deck of cards, analyze seventy years of S&P 500 prices, and pick relay teams for a community swim club.

By the end of this video course, you’ll understand that:

  • The functions in itertools operate on iterators and compose into data pipelines that use far less memory than list-based code.
  • batched() is the built-in way to split an iterable into chunks, and it replaces the hand-rolled grouper() recipe for most jobs.
  • combinations(), permutations(), and product() let you brute-force a problem, but they can trigger a combinatorial explosion.
  • count(), repeat(), cycle(), and accumulate() generate infinite sequences and running totals.
  • pairwise(), groupby(), takewhile(), and dropwhile() turn real data analysis tasks into short, readable pipelines.

The examples in this video course run on Python 3.15. You’ll need Python 3.12 or later for batched(), and Python 3.15 for unpacking in comprehensions.

Download

Course Slides (.pdf)

2.1 MB
Download

Sample Code (.zip)

316.0 KB

Become a Member to join the conversation.