map-like function on dict values?

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

Huaiyu Zhu <huaiyu at> 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:

groetjes, carel

More information about the Python-list mailing list