The language I am using is Python 3.10. I have been hunting a bug in my program for more than a week now, and it turns out that it was caused by my list comprehensions not giving the results I expected. I have written a simple example to showcase this behaviour:
alist = [1,2,3]
d = {}
for a in alist:
d[a] = lambda x: a + x
print([d[a](1) for a in alist])
for a in alist:
print(d[a](1))
This results to:
[4, 4, 4]
2
3
4
Does anyone know what is happening here? I guess that I will stop using dictionnaries of functions, but it still seems like it should work.