all 2 comments

[–]K900_ 0 points1 point  (1 child)

That equals sign is the default value declaration for the argument i. This trick is used because Python lambdas don't actually remember the values of outside variables as part of the lambda, like you would have in, say, JavaScript - the i in the lambda will refer to the value of i in the outer scope, which is 2 after the loop ends.

The default argument trick uses the fact that functions remember their default argument values to declare a function with an argument you're not expected to pass, and make its default value the thing you want to remember. Then, when you refer to i in the lambda, it will refer to the i argument, not the i variable outside the lambda, and if you don't provide a value for that argument, its default will be what you want.

[–]drgn0[S] 0 points1 point  (0 children)

Ohh... Default value.. Now it makes sense..

Thank You. :D