itertools.izip brokeness
Antoon Pardon
apardon at forel.vub.ac.be
Thu Jan 5 10:48:26 EST 2006
On 2006-01-04, rurpy at yahoo.com <rurpy at yahoo.com> wrote:
><rurpy at yahoo.com> wrote:
>> But here is my real question...
>> Why isn't something like this in itertools, or why shouldn't
>> it go into itertools?
>
>
> 4) If a need does arise, it can be met by __builtins__.map() or by
> writing: chain(iterable, repeat(None)).
>
> Yes, if youre a python guru. I don't even understand the
> code presented in this thread that uses chain/repeat,
And it wouldn't work in this case. chain(iterable, repeat(None))
changes your iterable into an iterator that first gives you
all elements in the iterator and when these are exhausted
will continue giving the repeat parameter. e.g.
chain([3,5,8],repeat("Bye")
Will produce 3, 5 and 8 followed by an endless stream
of "Bye".
But if you do this with all iterables, and you have to
because you don't know which one is the smaller, all
iterators will be infinite and izip will never stop.
--
Antoon Pardon
More information about the Python-list
mailing list