itertools
The standard library module of looping tools, such as islice, chain, product, combinations and groupby, that work lazily on any iterable.
In more detail
islice(iterable, n) takes the first n items of any iterator, even an endless one; combinations(items, 2) gives every pair. They save writing nested loops by hand.
Related terms
- iterator — An object that produces the items of a sequence one at a time, on request, instead of all at once.
- lazy evaluation — Postponing work until its result is actually needed, rather than doing it all in advance.
- generator — A function that can pause and resume, producing a series of values one at a time with yield, each only when it is requested.
Taught in
- Lists, Tuples, Sets, Dicts: Choosing One — Hands-on Python: Complete Video Course & Book
- A Standard Library Tour — Hands-on Python: Complete Video Course & Book