PEP 276 Simple Iterator for ints (fwd)

Rainer Deyke root at rainerdeyke.com
Tue Nov 27 23:23:17 EST 2001


"Peter Hansen" <peter at engcorp.com> wrote in message
news:3C045F92.AD720B at engcorp.com...
> Greg Ewing wrote:
> >
> > While trying to think of a range syntax that looks
> > unambiguously half-open without clashing with list
> > or tuple constructors, the following blindingly
> > obvious solution occurred to me:
> >
> >   for 0 <= i < 5:
> >     ...
>
> -1 for being ambiguous to newbies.  What would
> that mean, start and zero and go until four?
> Probably, but *I* read the previous thread on this.
> If a newbie had just learned about Python's ability
> to evaluate 0 <= i < 5 and return 1 or 0 for true/false
> the above might be a little perplexing.  Is it like
> for 1: if i is in that range, and for 0: if not?

The same could be said for 'for i in range(5)', since 'i in range(5)' is an
expression that is roughly equivalent to '0 <= i < 5'.

> Just in typing the above I had to hit backspace
> three times to type it right.  May "look" nice
> to some, but too obscure to others I think.
> Why fix what doesn't need fixing?

Having written several programs where the vast majority of 'for' loops were
in the form 'for something in range(something_else)', I would appreciate the
syntax sugar of 'for i in 5'.  All the other suggestions strike me as worse
than 'range'.


--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the Python-list mailing list