Python itertools By Example

Stephen Gruppetta 17 Lessons 50m Updated advanced python stdlib

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.

What’s Included:

  • 17 Lessons
  • Video Subtitles and Full Transcripts
  • 2 Downloadable Resources
  • Accompanying Text-Based Tutorial
  • Interactive Quiz to Check Your Progress
  • Q&A With Python Experts: Ask a Question
  • Certificate of Completion

Downloadable Resources:

About Stephen Gruppetta

Stephen obtained a PhD in physics and worked as a physicist in academia for over a decade before becoming a Python educator. He's constantly looking for simple ways to explain complex things in Python.

» More about Stephen

Each tutorial at Real Python is created by a team of developers so that it meets our high quality standards. The team members who worked on this tutorial are:

← Browse All Courses