Generating functions inside loop with lambda expression in python [duplicate]
As others have stated, scoping is the problem. Note that you can solve this by adding an extra argument to the lambda expression and assigning it a default value: >> def makeFun(i): return lambda: i … >>> a = [makeFun(i) for i in range(10)] >>> b = [lambda: i for i in range(10)] >>> c … Read more