Iterators
Let's discuss iterators and their types.
We'll cover the following...
Python provides a great module for creating our own iterators.
The
module we are referring to is itertools
. The tools provided by
itertools
are fast and memory efficient. We will use these building blocks to create our own specialized iterators that can be used for efficient looping.
In this chapter, we will be looking at examples of each building block so that by the end we will understand how to use them for our own code bases.
Let’s get started by looking at some infinite iterators!
The infinite iterators
The itertools
package comes with three iterators that can iterate
infinitely. What this means is that when we use them, you need to
understand that we will need ...