Why is the lambda expression only outputting the same result?
I expected to get the current value of the iterator and therefore the lambda expressions would output the numbers from 1 to 4 but that is obviously not the case.
I assume that the problem may have something to do with how the iterator is treated by the lambda expression but i could not find a answer to it yet. Thank you in advance
list = []
for i in range(5):
list.append(lambda:i)
for a in list:
print(a())
---OUTPUT---
4
4
4
4