Let's break down your lambda function. It is a function that accepts two arguments (x, i) and execute x in the power of i.
The for loop CREATES new lambda function every iteration. If you remove the i=i
, all the function would be the same: lambda x, i: x**i
So there is no mean to the for loop. They are all the same function.
Now the part i=i
means assign the value of i
from the for loop as a default argument for the function. The acts list would then have
[lambda x, i=1: x**i, lambda x, i=2: x**o, lambda ..]
Every iteration then creates a new lambda function, with a different value for i
.
I think the part you get confused is both your for loop and the lambda uses the variable name i
. However, the lambda defines a parameter (named i
) and the for loop uses different variable with the same name. As @Arndt said in the comments, you can change the lambda definition to lambda x, y=i: x**y
so it would be more clear.