Cleaner idiom for text processing?

Duncan Booth me at privacy.net
Wed May 26 07:47:24 EDT 2004


Peter Otten <__peter__ at web.de> wrote in
news:c91pft$rl0$04$1 at news.t-online.com: 

>> However, I'm not sure I trust either of these solutions. I know that
>> intuitively it would seem that both zip and izip should act in this
>> way, but is the order of consuming the inputs actually guaranteed
>> anywhere? 
> 
> I think an optimization that changes the order assumed above would be
> *really* weird. When passing around an iterator, you could never be
> sure whether the previous consumer just read 10 items ahead for
> efficiency reasons. Allowing such optimizations would in effect limit
> iterators to for loops. Moreover, the calling function has no way of
> knowing whether that would really be efficient as the first iterator
> might take a looong time to yield the next value while the second
> could just throw a StopIteration. If a way around this is ever found,
> checking izip()'s arguments for identity is only a minor complication.
> 

What happens if someone works out that izip can be made much faster by 
consuming its iterators from right to left instead of left to right? That 
isn't nearly as far fetched as reading ahead.

Passing the same iterator multiple times to izip is a pretty neat idea, but 
I would still be happier if the documentation explicitly stated that it 
consumes its arguments left to right.




More information about the Python-list mailing list