Learn itertools
Fast, memory-efficient building blocks for working with iterators
itertools provides lazy iterator functions implemented in C: infinite counters, chaining, slicing, grouping, running totals, batching and combinatorics. Combined, they express data-processing pipelines that handle huge or endless streams in constant memory. Knowing them replaces many hand-written loops with short, fast and correct code.
Before you start
How deep do you want to go?
1. EssentialsRead and write simple code, do the everyday basics
2. PracticalUse it productively at work, with the usual idioms
3. AdvancedThe less common features, performance and trade-offs
4. ExpertInternals and the edge cases experts know