looping to define a sequence of functions?
r.e.s.
r.s at ZZmindspring.com
Tue Jan 6 14:39:31 EST 2004
Suppose we want to define ten functions such that the
nth function of x simply returns x**n. Is there a way
to avoid explicitly writing ten function def's? (They
have to be ten distinct functions, not just a single
one like def f(n,x): return x**n.)
E.g., the following doesn't work:
f = {}
for n in range(10):
def f[n](x):
return x**n
Thanks.
--
r.e.s.
More information about the Python-list
mailing list