This was exactly what I was thinking of when I said > This is unavoidable in a for loop without breaking existing code, but I think > could (and should?) be changed in a list comprehension
Unfortunately, I was wrong in the last half of this statement. > since the comprehension control variable lives in an inner scope The inner scope can still be closed over via a lambda, such as in the following. I think that makes changing the semantics of either a breaking change. >>> funcs = [lambda: i for i in range(2)] >>> [f() for f in funcs()] [1, 1] # often not intended, but demonstrates the last-value-assigned semantics Eric _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/KPDOSMOB4YB5KUIM6WCCMGQIYGY3PGGO/ Code of Conduct: http://python.org/psf/codeofconduct/