Python Tutorial Was: Guido's regrets: filter and map
Grant Edwards
grante at visi.com
Tue Nov 26 13:57:59 EST 2002
In article <m28yzgz0wr.fsf at localhost.bris.ac.uk>, Michael Hudson wrote:
> grante at visi.com (Grant Edwards) writes:
>
>> In the case of reduce:
>>
>> sum = reduce(operator.add, valueList)
>>
>> How is that expressed any better with a list comprension?
>
> It's not. It's better expressed as a for loop, though.
sum = 0
for v in valueList:
sum += v
I think the former is more obvious, but I guess it's a matter
of taste.
> The for loop
> might well be quicker, too (cue Alex proving me wrong :).
--
Grant Edwards grante Yow! Mary Tyler Moore's
at SEVENTH HUSBAND is wearing
visi.com my DACRON TANK TOP in a
cheap hotel in HONOLULU!
More information about the Python-list
mailing list