How can I write the following code so that not all functions are the same?
>>> def g(x):
... l = []
... for i in range(1,10):
... def f(x):
... return x + i
... l.append(f)
... return l
The idea should be that g
returns a list of 9 functions where the first function returns x+1
the second x+2
etc. However, since in python everything is an object all previous function definition will be overwritten. How can I solve this?