"Snakes & Ladders: A Gentle Introduction to Generators and Iterators"
summary
Shows a working Snakes & Ladders implemented in Python that uses __iter__ and __next__ for the iterator protocol and yield and send for generators, with code and slides on GitHub. Demonstrates a 100-square board (10x10) built as a per-player generator so no external position tracking is needed, a generator that cycles player turns, and how a generator replaces building whole lists to stream values lazily. Notes iterator PEP 234 (Python 2.1) and generator PEP 255 (Python 2.2).
AI-written summary · about
chapters (8)
- 0:00Introduction
- 1:29Iterators and generators
- 6:22Iterator protocol
- 12:40Custom iterators
- 18:01Generators' advantages
- 24:03Generators vs functions
- 25:47Snakes and Ladders game
- 27:11Q&A
related talks
28mLoop better: a deeper look at iteration in Python
29mPythonic iterators and generators
25mLazy Looping: The Next Iteration
44mIterables and Iterators: Going Loopy With Python
02mTutorial Sneak Peek: "Lazy Looping in Practice..."
03mReimplement `itertools` for fun & profit
01h 48mSimple Games for Python Beginners
27mWhen to refactor your code into generators and how
