0

I am new to python, and require to generate something like the following, a list of similar functions using a loop and store them in a list.

I mean something along the lines of the following:

funcs = []
for i in range(1,11):
    def temp():
        print i
    funcs.append(temp)

Of course I know this won't work since its only temp being stored throughout the list and doing something like

funcs[3]
funcs[7]

will give

10
10

instead of

3
7

I don't wan't to use lambdas as the functions have to be a little more complex than what they allow.

nobody108
  • 1
  • 1
  • I really don't see how you could do that, but are you sure your functions cannot either have parameters to unify them into one or be wrote as one liners ? – asimoneau Jun 15 '15 at 18:06
  • @asimoneau - no, they can't – nobody108 Jun 15 '15 at 18:09
  • 1
    Just to clarify why the linked question answers your question. What you were doing does make separate functions. However, they were all working with the same version of `i`. The linked question tells you how to avoid that. – neil Jun 15 '15 at 18:12

0 Answers0