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

Bengt Richter bokr at oz.net
Tue Nov 26 12:59:27 EST 2002


On 26 Nov 2002 16:10:17 GMT, grante at visi.com (Grant Edwards) wrote:

>In article <mailman.1038322838.8306.python-list at python.org>, sismex01 at hebmex.com wrote:
>
>> Anyway, to each it's own.  But I do concurr with those who
>> say that with the acquisition of list comprehensions, map(),
>> reduce(), filter(), lambda() et-al, should be on the road
>> to deprecation and eventual elimination, being the black
>> un-pythonic sheep of the family.
>
>I see how you use list comprehensions to replace map and
>filter, but 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?
>
>In the case of reduce:
>
>  sum = reduce(operator.add, valueList)
>
>How is that expressed any better with a list comprension?
>
I don't think better is possible, but worse is (see my other
post in this thread ;-)

BTW, I used id as a sentinel, so it's vulnerable if the input sequence
contains a reference to id. I should really have generated an
internal-to-the-list-comprehension sentinel instead.

Regards,
Bengt Richter



More information about the Python-list mailing list