Iterating Efficiently in Python with itertools
summary
Concrete examples of Python’s itertools are presented: using count, cycle, and repeat for infinite sequences and round‑robin patterns; chain and chain.from_iterable to flatten logs without loading whole files; and zip_longest with fillvalue to avoid losing data. Demonstrates lazy filtering and slicing with compress and islice, generating combinations, permutations, and Cartesian products (for brute‑force password enumerations), and shows a benchmark where 20,160 combinations drop from ~93.7 ms to ~15.1 ms using itertools while avoiding crashes from loading huge ranges into memory.
AI-written summary · about
chapters (10)
- 0:00Welcome
- 1:25Efficient iteration
- 3:52Iterators and generators
- 8:06What are itertools
- 11:34Iteration tools
- 16:08Combining iterables
- 22:11Cartesian products and permutations
- 26:22Filtering and grouping
- 29:14Efficiency tips
- 31:21Conclusion
related talks
29mPythonic iterators and generators
33mA tour of the module itertools
24mMeta Generators: Playing Safe with Long Sequences
52mPython Tips, Tricks, and Idioms
28mLoop better: a deeper look at iteration in Python
44mIterables and Iterators: Going Loopy With Python
02mTutorial Sneak Peek: "Lazy Looping in Practice..."
25mLazy Looping: The Next Iteration
