A small code snippet from python 3.7.6 which completely has blown my mind:
def func(e, k):
print(k + e)
for f in [lambda e: func(e, k) for k in ['T', 'E', 'K']]:
for e in range(3):
f(str(e))
As an output I get:
K0
K1
K2
K0
K1
K2
K0
K1
K2
Is it a bug or a feature of Python? Because if you replace lambda
with functools.partial
everything works as expected!