storing references instead of copies in a dictionary
mk
mrkafk at gmail.com
Thu Jul 17 11:05:57 EDT 2008
> def f2(arg):
> return "f2 "+arg
>
> def f1(arg):
> return "f1 "+arg
>
> a={"1":"f1","2":"f2"}
> print [eval(x[1])(x[0]) for x in a.items()]
> def f2(arg):
> return "New f2 "+arg
> print [eval(x[1])(x[0]) for x in a.items()]
Neat trick, if probably dangerous in some circumstances. Anyway, thanks,
I didn't think of that.
> Don't know if this is any use to you..
At least I learned something. :-)
More information about the Python-list
mailing list