I need to generate a list of slightly different functions to be dynamically constructed:
def f(p,x):
print("f", p, x)
a=[]
for param in ('param_A', 'param_B'):
a.append( lambda x: f(param, x) )
Result:
IN: a[0](0)
OUT: f param_B 0
IN: a[1](1)
OUT: f param_B 1
While I will probably solve the problem by using functors instead, would be interesting to know the mechanics of variable binding and what is the simple fix for the above example