| 1 | initial version |
It's good to know the exec function - a powerful tool for "code generation":
sage: for k in range(1001):
....: exec("f_%d = lambda x:sin(%d*x)"%(k,k))
....:
sage: f_11(2)
sin(22)
I don't know what are the risks of using it (sometimes with great power comes great nagging about "bad programming habits", the most famous example is 'goto' commands).
"exec" also has a less powerful brother "eval", which does not help for your needs, but is also good to know (being less powerful he is probably less dangerous).
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.