looping to define a sequence of functions?
r.e.s.
r.s at ZZmindspring.com
Tue Jan 6 14:39:31 EST 2004
More information about the Python-list mailing list
Tue Jan 6 14:39:31 EST 2004
- Previous message (by thread): looping to define a sequence of functions?
- Next message (by thread): looping to define a sequence of functions?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Previous message (by thread): looping to define a sequence of functions?
- Next message (by thread): looping to define a sequence of functions?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list