[Python-iterators] While we're at it...

Quinn Dunkan quinn at regurgitate.ugcs.caltech.edu
Fri Jun 29 18:40:26 EDT 2001


On Fri, 29 Jun 2001 14:34:44 -0700, David Eppstein <eppstein at ics.uci.edu> wrote:
>In article <mailman.993846826.12787.python-list at python.org>,
> "Tim Peters" <tim.one at home.com> wrote:
>
>> - The following functions were generalized to work nicely with iterator
>>   arguments:
>>     map(), filter(), reduce(), zip()
>
>Is there a PEP for this?  It doesn't seem to be in 234.
>Can I assume that "work nicely" means they act like simple generators in 
>yielding partial results even when their inputs are infinite sequences?

I assume they all still return normal sequences, not iterators, since
returning an iterator would break a lot of code.  So they can take iterator
args now, but an infinite iterator will hang just the same.

Of course, an iterator map would be useful:

def iter_map(f, seq):
    for o in seq:
        yield f(o)

which would work with an infinite sequence.  It's sort of another way to write
a lazy list, after all.



More information about the Python-list mailing list