functional programming with map()

Paul Rubin phr-n2002a at nightsong.com
Mon Feb 25 00:54:47 EST 2002


"Emile van Sebille" <emile at fenx.com> writes:

> "Paul Rubin" 
> > Both of those build up a new list of the results, instead of
> > discarding the values.  If the f function takes an integer and
> > computes a 20-megabyte structure, you've got a problem.  
> 
> If you know it's coming, throw it away first:
> 
> [x.f() and None for x in items]

OK, but that buidls a list of None as long as the item list.  Not
so bad, since it gets reclaimed right away, but still unsatisfying.

> filter(None,[x.f() and None for x in items])
> 
> returns an empty list vs 0 for the reduce.  

Again there's this intermediate list that's as long as the original list.

Do you see a way around that?

Thanks



More information about the Python-list mailing list