Itertools

Learn about functions that the itertools library provides for iteration.

We have mentioned several libraries in other sections of this course. This chapter tells you where to find them and lists further areas to explore.

itertools

itertools is a standard Python library – it is part of Python and doesn’t need any extra installation.

It contains a number of useful extra functions for iteration. Here are some of the highlights; refer to the documentation on python.org for a full list.

Infinite iterators

These are iterators that go on forever.

count

count(start, [step]) produces an infinite series of incrementing values with an initial start value.

For example:

count(0) # Creates 0, 1, 2 ...

It behaves like range but with the end ...