Pythonic iterators and generators
summary
Shows exact code patterns and library calls: use zip then dict for pairing, use itertools.chain and chain.from_iterable (added in Python 2.6) to flatten streams, use itertools.product and itertools.combinations to build Cartesian products and power sets, implement custom iterators with __iter__ and next and write yield-based generators for lazy sequences. Demonstrates a Fibonacci iterator, a deck-of-cards iterable, using itertools.count for infinite streams, and using generators plus itertools.islice to process huge CSVs without loading everything.
AI-written summary · about
chapters (10)
- 0:00Introduction
- 0:51Warm-up exercises
- 5:47Advanced itertools examples
- 7:32Understanding iterators
- 11:27Built-in iterators and uses
- 17:25Creating custom iterators
- 18:36Introduction to generators
- 22:31Generators in practice
- 25:43Conclusion and summary
- 27:31Q&A session
related talks
32mIterating Efficiently in Python with itertools
33mA tour of the module itertools
27mWhen to refactor your code into generators and how
03mReimplement `itertools` for fun & profit
25mLazy Looping: The Next Iteration
28mLoop better: a deeper look at iteration in Python
44mIterables and Iterators: Going Loopy With Python
27m"Snakes & Ladders: A Gentle Introduction to Generators and Iterators"
