What is Python itertools module?
Answer
The itertools module provides memory-efficient tools for working with iterators. Infinite iterators: count(start, step) (0, 1, 2...), cycle(iterable) (A, B, C, A, B, C...), repeat(obj, times). Combining: chain(a, b, c) (flatten), chain.from_iterable([[1,2],[3,4]]), zip_longest(a, b, fillvalue=None). Filtering: islice(it, stop) (lazy slice), takewhile(pred, it), dropwhile(pred, it), filterfalse(pred, it). Grouping: groupby(it, key) — groups consecutive identical keys. Combinatorics: product(a, b) (Cartesian product), permutations(it, r), combinations(it, r), combinations_with_replacement(it, r). All are lazy (generator-based). Use itertools for memory-efficient data pipelines when working with large datasets.
Previous
What is Python's structural pattern matching (match/case)?
Next
What is Python's __all__ variable?