comprehensions was Re: Switch statements again

Bengt Richter bokr at
Fri Jan 17 17:26:16 CET 2003

On Fri, 17 Jan 2003 04:05:09 -0800, Erik Max Francis <max at> wrote:

>Ville Vainio wrote:
>> Of course, there is still the embarrassing issue of the list
>> comprehension variable not being local to the list comprehension. Why,
>> oh why won't people pre-deprecate it... at least in the documentation.
>> Any hope to get it into the tutorial/lang reference for 2.3 :)?
>Probably for the same reason that other iterative constructs that
>introduce variables don't make them local to that structure either:
>>>> [x for x in range(10)]
>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>>> x
>>>> for y in range(10): print y,
>0 1 2 3 4 5 6 7 8 9
>>>> y
>If one annoys you, surely the other would, too?

I think the case is stronger for making list comprehension variables
have their own scope, because it is an expression, whereas for ... is a
statement. If statement suites of some kind got their own local scope,
then for variables should probably be local to the suite block, but we
don't have that.


List comprehensions shoot stray name-bullets into the current name crowd,
and IMO that's bad for an expression to do.

<except ExcessiveMetaphorElaborationError:>
   <pass ;-)>

Bengt Richter

More information about the Python-list mailing list