[Python-3000] map() Returns Iterator

Aahz aahz at pythoncraft.com
Tue Aug 7 16:56:02 CEST 2007


On Mon, Aug 06, 2007, Guido van Rossum wrote:
>
> I've always made a point of suggesting that we're switching to
> returning iterators instead of lists from as many APIs as makes sense
> (I stop at str.split() though, as I can't think of a use case where
> the list would be so big as to be bothersome).

s = ('123456789' * 10) + '\n'
s = s * 10**9
s.split('\n')

Now, maybe we "shouldn't" be processing all that in memory, but if your
argument applies to other things, I don't see why it shouldn't apply to
split().  Keep in mind that because split() generates a new string for
each line, that really does eat lots of memory, even if you switch to
10**6 instead of 10**9, which seems like a very common use case.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

This is Python.  We don't care much about theory, except where it intersects 
with useful practice.  


More information about the Python-3000 mailing list