PEP 276 Simple Iterator for ints (fwd)

James_Althoff at i2.com James_Althoff at i2.com
Wed Nov 28 20:45:27 EST 2001


David Eppstein wrote:
>I would rather view a for-loop as
>  "for" expression:
>where (currently) the expression must have as its top level operation the
>"in" operation and the lhs must be a variable.  The variable is set in all

>possible ways that make the expression true.  From this point of view,
"for
>x in 5" looks really ugly, and "for 0 <= x < 5" makes a lot more sense: we

>now simply allow one more kind of expression in a for loop, one where the
>top level is a three-way comparison and the middle side of the comparison
>must be a variable.

I would have guessed, though, that given the current direction of Python
vis-a-vis iterators that

    for 0 <= x < 5:

would have to mean something like "0 <= x < 5" is special syntax built into
the for-loop statement that generates an iterator that enumerates the
integers 0,1,2,3,4.  It happens to look just like an expression which
*outside* the context of a for-loop evaluates to 0 or 1 instead of
producing an iterator (as was pointed out previously by Peter Hansen).

Jim





More information about the Python-list mailing list