Python · Functions, Closures and Iteration · Intermediate · 26 min read
Python Iterators and the Iteration Protocol: Writing Iterators, itertools Recipes and Iterator Pitfalls
Go deeper on iteration. Learn iterable versus iterator precisely, the two-method protocol and the __getitem__ fallback, writing re-iterable collections and one-shot iterators, iter with a sentinel, peeking and pushing back, batching and windowing, itertools recipes, zip and unpacking behaviour, consuming iterators safely, and async iteration.
Create an account to start
Create a free account to see what this lesson covers
- Every free lesson in every section, in full
- Track your progress and pick up where you left off
- Free practice questions and an incident simulation
- Takes under a minute: name, email and a password
No card needed. Full access to Python is a paid upgrade you can choose later.