Chaining Iterators

Learn how to chain iterators using a generator.

We'll cover the following

Now we will do something more useful. We will chain two iterators together so that you get a single iterator that returns all the values of one iterator, followed by all the values of another iterator.

Identity generator

First, we will look at an identity generator. This provides a way to iterate over an existing iterator. It is not very useful in itself (you could just iterate over the original iterator directly), but it is a step in the right direction.

Get hands-on with 1200+ tech skills courses.