map-like function on dict values?

Skip Montanaro skip at pobox.com
Sat Mar 2 10:23:44 EST 2002


    Raymond> The mapvalue test needs a tune-up.  Skipping the operator
    Raymond> module and calling setitem directly speeds things up a bit:

    Raymond> def tunedmap(f, d):
    Raymond>         return map( d.__setitem__, d.keys(), map(f, d.values()) )

Ah, yes.  operator.setitem would only be needed if you were using multiple
dictionaries.  Good point.

-- 
Skip Montanaro (skip at pobox.com - http://www.mojam.com/)




More information about the Python-list mailing list