itertools.izip brokeness

rurpy at rurpy at
Wed Jan 4 17:59:31 EST 2006

> I don't understand this.   Why do you need look ahead?

Just before I posted, I got it (I think) but didn't want to
rewrite everything.  The need for unget() (or peek(), etc)
is to fix the thrown-away-data problem in izip(), right?

As an easier alternative, what about leaving izip() alone
and simply documenting that behavior.  That is, izip()
is not appropriate for use with unequal length iterables
unless you don't care what happens after the shortest,
and the state of the iterables is undefined after izip().

Then have an izip2() or a flag to izip() that changes it's
behavior, that results in iteration to the end of the
longest sequence.

This seems to me clean and symetrical -- one form
for iteration up to the shortest, the other form iterates
to the longest.

More information about the Python-list mailing list