I am working in Python 2.7 and need to generate a list of functions each of which has a different default argument but where the functions are explained. This is not the best explanation, but I think the example below clarifies my question. Is there a way of doing this?
function_list = []
for i in range(10):
function_list.append(lambda x: myfunc(i,x))
def myfunc(a,b):
print a + b
This doesn't work, as, in this example, all functions in the function list return 9 + x
In the example above "x" is a separate variable to be passed to the function in a different way.
I realise that this is a pretty ugly construction but have inherited a large amount of code around this that would need to be changed to avoid this.