def out0(x):
print 0
def out1(x):
print 1
m = [out0,out1]
l = [lambda: x(0) for x in m]
l[0]()
l[1]()
>>>
1
1
def out0(x):
print 0
def out1(x):
print 1
m = [out0,out1]
l = [lambda: m[0](0),lambda: m[1](0)]
l[0]()
l[1]()
>>>
0
1
def out0(x):
print 0
def out1(x):
print 1
m = [out0,out1]
l = [lambda: x(0) for x in m]
l[0]()
l[1]()
def out0(x):
print 0
def out1(x):
print 1
m = [out0,out1]
l = [lambda: m[0](0),lambda: m[1](0)]
l[0]()
l[1]()
Octansx - находится во внешней по отношению к лямбде области видимости. После формирования списка x равно последнему значению из m, т.е. out1. Так что все логично.результат:def out0(x):
print 0
def out1(x):
print 1
m = [out0,out1]
l = [lambda: x(0) for x in m]
l[0]()
l[1]()
>>>
1
1
from functools import partial
def out0(x):
print 0, x
def out1(x):
print 1, x
m = [out0,out1]
l = [partial(x, 0) for x in m]
In [52]: l[0]()
0 0
In [53]: l[1]()
1 0
def partial(func, *args, **keywords):
def newfunc(*fargs, **fkeywords):
newkeywords = keywords.copy()
newkeywords.update(fkeywords)
return func(*(args + fargs), **newkeywords)
newfunc.func = func
newfunc.args = args
newfunc.keywords = keywords
return newfunc
[lambda x=x,y=y: x(y) for x, y in zip(funs, pars)]
map(lambda x, y: lambda : x(y), funs, pars)