This question already has an answer here:
- Weird behavior: Lambda inside list comprehension 6 answers
I'm playing with lambda functions inside of list comprehension, and found some weird behaviour
x = [(lambda x: i) for i in range(3)]
print(x[0](0)) #print 2 instead of 0
print(x[1](0)) #print 2 instead of 1
print(x[2](0)) #print 2
Can someone explain why the result is not that I expect?