Life-time of temporary variables in list comprehensions
zyzhu2000 at gmail.com
Tue Oct 23 19:02:48 CEST 2007
If I have a list comprehension:
c = "ABC"
[1.0 if c=='A' else c='B' for c in ab]
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 local to list comprehensions.
My question is why is this and is there any way to make c local to
More information about the Python-list