Incorrect scope of list comprehension variables

Ethan Furman ethan at stoneleaf.us
Sun Apr 4 08:50:01 EDT 2010


Steve Howell wrote:
> On Apr 3, 9:58 pm, Tim Roberts <t... at probo.com> wrote:
> 
>>Alain Ketterlin <al... at dpt-info.u-strasbg.fr> wrote:
>>
>>
>>>I've just spent a few hours debugging code similar to this:
>>
>>>d = dict()
>>>for r in [1,2,3]:
>>>   d[r] = [r for r in [4,5,6]]
>>>print d
>>
>>Yes, this has been fixed in later revisions, but I'm curious to know what
>>led you to believe that a list comprehension created a new scope.  I don't
>>that was ever promised.
> 
> 
> Common sense about how programming languages should work?  As
> confirmed by later revisions?

Common sense?  About *somebody else's* idea of how a programming 
language should work?

Please.  Experiment and read the manual.

~Ethan~



More information about the Python-list mailing list