Re: Odd behaviour with list comprehension

2008-03-30 Thread Steve Holden
Terry Reedy wrote: > "Steve Holden" <[EMAIL PROTECTED]> wrote in message [...] > | Well, the fact that the bound variable in the list comprehension does > | indeed remain outside the construct is simply the result of an > | over-zealous wish to emulate for loop semantics. The original reasoning, >

Re: Odd behaviour with list comprehension

2008-03-30 Thread Terry Reedy
"Steve Holden" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Micah Cowan wrote: | > "Jerry Hill" <[EMAIL PROTECTED]> writes: | > | >> On Fri, Feb 29, 2008 at 10:01 PM, Ken Pu <[EMAIL PROTECTED]> wrote: | >>> Is there a way for me keep the iterating variable in list | >>> compre

Re: Odd behaviour with list comprehension

2008-03-30 Thread Steve Holden
Micah Cowan wrote: > "Jerry Hill" <[EMAIL PROTECTED]> writes: > >> On Fri, Feb 29, 2008 at 10:01 PM, Ken Pu <[EMAIL PROTECTED]> wrote: >>> Is there a way for me keep the iterating variable in list >>> comprehension local to the list comprehension? >> Kind of. You can use a generator expression

Re: Odd behaviour with list comprehension

2008-02-29 Thread Jeffrey Froman
Ken Pu wrote: > So the list comprehension actually creates a variable x which is > somewhat unexpected. > Is there a way for me keep the iterating variable in list > comprehension local to the list comprehension? Not with a list comprehension, but generator expressions do not leak their iterating

Re: Odd behaviour with list comprehension

2008-02-29 Thread Micah Cowan
"Jerry Hill" <[EMAIL PROTECTED]> writes: > On Fri, Feb 29, 2008 at 10:01 PM, Ken Pu <[EMAIL PROTECTED]> wrote: >> Is there a way for me keep the iterating variable in list >> comprehension local to the list comprehension? > > Kind of. You can use a generator expression instead of a list > compr

Re: Odd behaviour with list comprehension

2008-02-29 Thread Jerry Hill
On Fri, Feb 29, 2008 at 10:01 PM, Ken Pu <[EMAIL PROTECTED]> wrote: > Is there a way for me keep the iterating variable in list > comprehension local to the list comprehension? Kind of. You can use a generator expression instead of a list comprehension, and those don't leak their internal varia

Re: Odd behaviour with list comprehension

2008-02-29 Thread Micah Cowan
"Ken Pu" <[EMAIL PROTECTED]> writes: > Hi all, > > I observed an interesting yet unpleasant variable scope behaviour with > list comprehension in the following code: > > print [x for x in range(10)] > print x > > It outputs: > > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > 9 > > So the list comprehension actu

Odd behaviour with list comprehension

2008-02-29 Thread Ken Pu
Hi all, I observed an interesting yet unpleasant variable scope behaviour with list comprehension in the following code: print [x for x in range(10)] print x It outputs: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 9 So the list comprehension actually creates a variable x which is somewhat unexpected. Is th