Re: Life-time of temporary variables in list comprehensions

2007-10-23 Thread beginner
On Oct 23, 12:02 pm, beginner <[EMAIL PROTECTED]> wrote: > Hi All, > > If I have a list comprehension: > > ab=["A","B"] > c = "ABC" > [1.0 if c=='A' else c='B' for c in ab] > print c > > >>"B" > > My test shows that if c is not defined before the list comprehension, > it will be created in the list

Re: Life-time of temporary variables in list comprehensions

2007-10-23 Thread Steven D'Aprano
On Tue, 23 Oct 2007 17:02:48 +, beginner wrote: > My test shows that if c is not defined before the list comprehension, it > will be created in the list comprehension; if it is defined before the > list comprehension, the value will be overwritten. In other words, temp > variables are not loca

Re: Life-time of temporary variables in list comprehensions

2007-10-23 Thread Diez B. Roggisch
beginner schrieb: > Hi All, > > If I have a list comprehension: > > ab=["A","B"] > c = "ABC" > [1.0 if c=='A' else c='B' for c in ab] > print c > >>> "B" > > My test shows that if c is not defined before the list comprehension, > it will be created in the list comprehension; if it is defined be

Re: Life-time of temporary variables in list comprehensions

2007-10-23 Thread Carsten Haese
On Tue, 2007-10-23 at 17:02 +, beginner wrote: > Hi All, > > If I have a list comprehension: > > ab=["A","B"] > c = "ABC" > [1.0 if c=='A' else c='B' for c in ab] "c='B'" is invalid syntax. Maybe you mean "c=='B'". That doesn't make much sense, but at least it's correct syntax. > print c >

Life-time of temporary variables in list comprehensions

2007-10-23 Thread beginner
Hi All, If I have a list comprehension: ab=["A","B"] c = "ABC" [1.0 if c=='A' else c='B' for c in ab] print c >>"B" My test shows that if c is not defined before the list comprehension, it will be created in the list comprehension; if it is defined before the list comprehension, the value will