itertools.izip brokeness

Bengt Richter bokr at oz.net
Mon Jan 9 21:18:27 EST 2006


On 9 Jan 2006 08:19:21 GMT, Antoon Pardon <apardon at forel.vub.ac.be> wrote:

>Op 2006-01-05, Bengt Richter schreef <bokr at oz.net>:
>> On 5 Jan 2006 15:48:26 GMT, Antoon Pardon <apardon at forel.vub.ac.be> wrote:
[...]
>> But you can fix that (only test is what you see ;-) :
>
>Maybe, but not with this version.
>
>> >>> from itertools import repeat, chain, izip
>> >>> it = iter(lambda z=izip(chain([3,5,8],repeat("Bye")), chain([11,22],repeat("Bye"))):z.next(), ("Bye","Bye"))
>> >>> for t in it: print t
>>  ...
>>  (3, 11)
>>  (5, 22)
>>  (8, 'Bye')
>>
>> (Feel free to generalize ;-)
>
>The problem with this version is that it will stop if for some reason
>each iterable contains a 'Bye' at the same place. Now this may seem
>far fetched at first. But consider that if data is collected from
ISTM the job of choosing an appropriate sentinel involves making
that not only far fetched but well-nigh impossible ;-)

>experiments certain values may be missing. This can be indicated
>by a special "Missing Data" value in an iterable. But this "Missing
>Data" value would also be the prime canidate for a fill parameter
>when an iterable is exhausted.
>
ISTM that confuses "missing data" with "end of data stream."
I assumed your choice of terminating sentinel ("Bye") would not have
that problem ;-)

Regards,
Bengt Richter



More information about the Python-list mailing list