[Python-Dev] accumulator display syntax

Skip Montanaro skip at pobox.com
Tue Oct 21 16:23:15 EDT 2003

    Guido> Here's the rule I'd propose for iterator comprehensions, which list
    Guido> comprehensions would inherit:

    Guido>     [<expr1> for <vars> in <expr2>]

    Guido> The variables in <vars> should always be simple variables, and
    Guido> their scope only extends to <expr1>.  If there's a variable with
    Guido> the same name in an outer scope (including the function
    Guido> containing the comprehension) it is not accessible (at least not
    Guido> by name) in <expr1>.  <expr2> is not affected.

I thought the definition for list comprehension syntax was something like

        <expr> for <vars> in <expr>
               [ for <vars> in <expr> ] *
               [ if <expr> ] *

The loop <vars> in an earlier for clause should be visible in all nested for
clauses and conditional clauses, not just in the first <expr>.


More information about the Python-Dev mailing list