Re: variable scope in list comprehensions

2008-04-05 Thread Steve Holden
Duncan Booth wrote: > Steve Holden <[EMAIL PROTECTED]> wrote: > >>> For a moment I thought that maybe list comprehension has its own >>> scope, but it doesn't seem to be so: >>> print [[y for y in range(8)] for y in range(8)] >>> print y >>> >>> Does anybody understand it? >>> >>> >> This isn't _a

Re: variable scope in list comprehensions

2008-04-04 Thread Piotr Sobolewski
Duncan Booth wrote: > For the OP, in some languages (e.g. C) 'for' loops typically calculate > the value of the loop control variable based on some expression > involving the previous value. Python isn't like that. In Python the data > used to compute the next value is stored internally: you canno

Re: variable scope in list comprehensions

2008-04-04 Thread Duncan Booth
Steve Holden <[EMAIL PROTECTED]> wrote: >> For a moment I thought that maybe list comprehension has its own >> scope, but it doesn't seem to be so: >> print [[y for y in range(8)] for y in range(8)] >> print y >> >> Does anybody understand it? >> >> > This isn't _a_ list comprehension, it's *tw

Re: variable scope in list comprehensions

2008-04-03 Thread Steve Holden
Piotr Sobolewski wrote: > Hello, > > there is something I don't understand about list comprehensions. > > I understand how does this work: > print [[y for x in range(8)] for y in range(8)] > > However I don't understand why this one works: > print [[y for y in range(8)] for y in range(8)] > > I

variable scope in list comprehensions

2008-04-03 Thread Piotr Sobolewski
Hello, there is something I don't understand about list comprehensions. I understand how does this work: print [[y for x in range(8)] for y in range(8)] However I don't understand why this one works: print [[y for y in range(8)] for y in range(8)] In this second example I have one loop nested i