count in 'for ... in ...'

Quinn Dunkan quinn at hork.ugcs.caltech.edu
Tue Nov 6 23:54:36 EST 2001


On Tue, 6 Nov 2001 12:28:22 -0500 (EST), Steven D. Majewski
<sdm7g at Virginia.EDU> wrote:
>>>> from __future__ import generators
>>>> def izip( *args ):
>...     its = map( iter, args )
>...     while 1: 
>...             yield map( lambda x: x.next(), its )

Or maybe xzip, since 'x' seems to be the conventional prefix for a non-strict
variant.

Whenever I find myself working with lazy lists/dicts, I find myself writing
non-strict versions of map, zip, filter, etc.  Since generators will make lazy
lists so much more fun, I'll probably be using more of them in the __future__.

I'm pretty sure the question has already been asked back when generators and
iterators were a hot topic, but would it be advisable to extend the standard
list processing functions to also work lazily on iterators?

Since list comprehensions already use the sequence protocol and should work
nicely with generators, is it "better style" (more polymorphic) to use a list
comp instead of zip, filter, map, etc.?



More information about the Python-list mailing list