Itertools
The `itertools` module provides a collection of fast, memory-efficient tools for working with iterators. They form an "iterator algebra" for building complex iteration pipelines. The guide walks through Infinite Iterators, Combining Iterables, Permutations & Combinations, Grouping & Filtering, Slicing & Selecting. `count(start=0, step=1)` yields infinite consecutive numbers. `cycle(iterable)` yields elements repeatedly in a loop. `repeat(elem, times=None)` yields an element repeatedly. Use with `zip()` or `map()` to limit the infinite iterators. `chain(iter1, iter2)` concatenates iterables sequentially. `zip_longest(*iterables, fillvalue=None)` zips unequal iterables filling missing values. `product(*iterables, repeat=1)` computes the Cartesian product as tuples. `chain.from_iterable(iterables)` chains from a single iterable of iterables. `permutations(iterable, r)` yields all ordered arrangements of length r. `combinations(iterable, r)` yields all unordered combinations without replacement. `combinations_with_replacement(iterable, r)` yields combinations where elements can repeat. All yield tuples. The guide is organized into 5 sections that build on each other, each pairing a prose explanation with runnable code. Browse the individual functions covered by this guide in the Itertools Module category.