Tee

Contents

Python iterators and Haskell lists are different things. We have not yet had to reckon with this fact, but for this lesson we can no longer look past the distinction.

Python iterators are mutable

First we’ll set up an example to illustrate why itertools.tee exists. Let’s say we start with an iterator that represents all of the natural numbers starting from 1:

Sign up for access to the full page, plus the complete archive and all the latest content.