map-like function on dict values?

Erik Max Francis max at alcyone.com
Wed Feb 27 20:54:37 EST 2002


Huaiyu Zhu wrote:

> 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.

In 2.2 you can use map on a dictionary; it is equivalent to mapping
against its keys.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ Laws are silent in time of war.
\__/ Cicero
    Esperanto reference / http://www.alcyone.com/max/lang/esperanto/
 An Esperanto reference for English speakers.



More information about the Python-list mailing list