generic class for everything?
Alex Martelli
aleax at aleax.it
Sat Mar 29 18:58:14 EST 2003
Rob Brown-Bayliss wrote:
...
> Rather than do the eqivalant of "if somedict has key "x" then
> function_x(somedict[x])" i would rather do something like:
>
> for key in somedict: key(value)
>
> But am not sure how to get there?
functions CAN be keys in dictionaries. I'm not sure
where you want to get that "value" from, but assuming
it's the dict entry for the key, e.g.:
>>> def f(x): print 'f', x
...
>>> def g(x): print 'g', x
...
>>> dd={f:23, g:45}
>>> for k in dd: k(dd[k])
...
g 45
f 23
>>>
Alex
More information about the Python-list
mailing list