Python Tutorial Was: Guido's regrets: filter and map

Greg Ewing see_reply_address at something.invalid
Tue Nov 26 23:42:15 EST 2002


Grant Edwards wrote:

> I don't understand why list comprehensions are
> touted as a replacement for reduce and lambda.  I use lamba
> almost exclusively to generate anonymous functions that are
> passed to GUI widgets.  How does a list comprehension solve
> that problem?


It doesn't. A list comprehension is a replacement
for map+lambda or filter+lambda -- nobody claims that
it replaces *all* uses of lambda. And it doesn't
replace reduce at all -- we've yet to see a construct
proposed to do that (aside from writing it out as
an explicit loop).

In the case of lambda, however, you can always get
the same effect using an explicitly declared function,
bound method, etc. So lambda isn't really  needed
anyway, regardless of whether list comprehensions
exist.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg




More information about the Python-list mailing list