Can someone explain to me why this is occurring?
It looks like the print statement is getting lazily evaluated, but the question then is where does the v come from, since it should just be the argument.
In languages such as OCaml a closure (lambda statement) effectively takes a snapshot of its environment and uses that, but python seems here to use the newest environment...
d = {}
def printf(v):
print(v)
for v in range(10):
d[v] = lambda:printf(v)
d[1]()
prints 9
in python2.7 and python3.6