I am looking at T.Scholak's gist
I will reproduce with Jupyter
def side_effecty_id(x):
print(x)
return x
Let's consider
lambdas_0 = tuple((lambda x: x >= side_effecty_id(i)) for i in range(10))
tuple(l(5) for l in lambdas_0)
Result
9
9
9
9
9
9
9
9
9
9
(False, False, False, False, False, False, False, False, False, False)
While
lambdas_1 = tuple((lambda i: lambda x: x >= side_effecty_id(i))(i) for i in range(10))
tuple(l(5) for l in lambdas_1)
Gives
0
1
2
3
4
5
6
7
8
9
(True, True, True, True, True, True, False, False, False, False)
I regard this as very good example. Why do we need double lambdas? I have compared lambdas_0 and lambdas_1
<function __main__.<genexpr>.<lambda>(x)>
and
<function __main__.<genexpr>.<lambda>.<locals>.<lambda>(x)>,
What does <locals>
denote?