map-like function on dict values?

Carel Fellinger cfelling at iae.nl
Thu Feb 28 16:19:29 EST 2002


Huaiyu Zhu <huaiyu at gauss.almadan.ibm.com> wrote:

> PS. The test and result:

Just for kicks I added a true iteritems, and it wins hands down:)
it's lean (no temporary list at all), it is fast and it stays readable.

> import operator
> from time import time
...
   def iteriteritems(f, d):
 	for k, v in d.iteritems():
 		d[k] = f(v)
...
 	timeit(iteriteritems, f, d)
> 	timeit(iteritems, f, d)
> 	timeit(mapvalue, f, d)

> # result
> 	
> 19.8180559874
> 4.17512202263

And my result on my old and crusty machine:

7.69514203072
36.7980870008
9.78200399876
-- 
groetjes, carel



More information about the Python-list mailing list