map-like function on dict values?
cfelling at iae.nl
Thu Feb 28 04:45:34 CET 2002
Huaiyu Zhu <huaiyu at gauss.almadan.ibm.com> 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. Something like
what about using an iterator, like
for k, v in dict.iteritems():
dict[k] = f(v)
would be interesting to know whether saving to build a (huge) list would
save you the time you need.
As for the C function, for each item you'll have to get to the python
interpreter to evaluate the `f(v)' call. My gut feeling would be that
that would be costly. But as you know, gut feelings are worthless,
time it instead.
More information about the Python-list