I know this doesn't work (because python assignment rules)
def foo(a, methods=[]):
m=[];
for bla in methods:
m.append(bla)
for i in range(3):
k = i
m.append(lambda x: x + k)
But this should work, according to quick'n'dirty google (because default assignment), and yet it doesn't. for i in range(3):
def bar(c, d=i): return c+d
m.append(lambda x: bar(x))
EDIT:
Ok, I'm something missing here.This doesn't capture the value of i
for i in range(3):
m.append(lambda x,i=i: x+i)
But this does. WTH?! for i in range(3):
m.append(lambda i=i: i)