map-like function on dict values?

Raymond Hettinger othello
Wed Feb 27 23:05:57 EST 2002


How about:

dict( map( lambda k,v: (k,f(v)), d.items() ) )

or

map( d.__setitem__, d.keys, map(f, d.values) )


Raymond

"Huaiyu Zhu" <huaiyu at gauss.almadan.ibm.com> wrote in message
news:slrna7r0hi.bkl.huaiyu at gauss.almadan.ibm.com...
> Is there a way to do this
>
> for k, v in dict.items():
>     dict[k] = f(v)
>
> without involving a Python for loop?  I'd imagine that a function
> implemented in C could speed things up quite a bit.  Something like
> either of the following
>
> mapvalue(f, dict)
> dict.mapvalue(f)
>
> Huaiyu





More information about the Python-list mailing list