Issue Tracker issues, and a bug in Python

Hosford, Aaron Michael aaron.hosford at west.com
Wed Nov 10 21:51:19 CET 2010


Hi all,

I found a bug in Python 2.7 involving dictionary comprehensions. I repeatedly tried to register on the Issue Tracker (http://bugs.python.org/) but never received a confirmation email, so I still can't log in and post it there. Maybe someone on this list can post it on my behalf:

>>> functions =  {x : lambda y: x + y for x in xrange(10)}
>>> functions[0](0)
9
>>>

The expression "functions[0](0)" should return 0, not 9. It looks like the scope for variable x is shared across the entire dictionary comprehension rather than having separate scope for each generated item.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-bugs-list/attachments/20101110/3bd289e7/attachment.html>


More information about the Python-bugs-list mailing list