I want to create a list of functions consisting of function objects created by a fixed base function but with different input parameters. I have written such code:
def f_base(name):
print "I am %s" % name
f_list = []
for name in ['A', 'B']:
f_list.append(
lambda : f_base(name)
)
f_list[0]()
f_list[1]()
The result is:
I am B
I am B
But I want to get:
I am A
I am B
Can someone explain why Python produces such output and what is the easiest way to get the result I need?