reduce() anomaly?

Alex Martelli aleax at aleax.it
Thu Nov 6 17:01:15 EST 2003


Jeremy Fincher wrote:

> Duncan Booth <duncan at NOSPAMrcp.co.uk> wrote in message
> news:<Xns942B93E4AE037duncanrcpcouk at 127.0.0.1>...
>> which can be written more concisely without the lambda:
>> 
>>   d = {}
>>   map(d.update, l)
> 
> Although he shouldn't be using map at all for this case; he's not
> using the resulting list.

Absolutely true.


> Just a plan for loop will suffice:
> 
> for otherDict in l:
>     d.update(otherDict)

And if one needs to get top performance, an _almost_ plain for loop
will give performance just as good as map (rather than, say, 15% worse
or so -- not a worry in 99.999% of the cases, of course...):

d_upda = d.update
for otherDictin l:
    d_upda(otherDict)

[the usual case of "manual constant subexpression hoisting" where the
constant subexpression is the attribute lookup for d.update ...).


Alex





More information about the Python-list mailing list