PEP 276 Simple Iterator for ints (fwd)
Peter Hansen
peter at engcorp.com
Wed Nov 28 09:38:23 EST 2001
David Eppstein wrote:
>
> Peter Hansen <peter at engcorp.com> wrote:
>
> > I agree that sounds like a worthy goal. I disagree that your
> > suggestion is any more likely to be understood by anyone,
> > other than perhaps a mathematician. [...]
>
> From context, it seems you mean Ewing's suggestion rather than mine, right?
Yes, quite right. Sorry. :)
> > Maybe we should look back to BASIC (for i = 1 to 5: next)
> > or one of the suggestions for something which looks more
> > explicitly like a list of items (for i in [0..5]) or
> > (for i in [0, 1, .. 5] ). Especially this latter would
> > definitely be understandable to anyone, IMHO.
>
> Your final option is very close to my suggestion, much earlier in this
> thread, which seems to be disliked by many due to its requiring closed
> intervals while other Python features use half-open ones.
I was skimming the thread by that point, but I can say only
that I don't see that there needs to be consistency between
these two things. range(5) is a function with a definition
which does what it does. It could just as well return
true or false, if that's what the docs said it did.
[0, 1, ... 5 ] looks like a list and should act like a list.
In fact, it should *produce* a list, or in the new world
an iterator. That list should "clearly" contain both 0
and 5. Anything else would be surprising.
I suppose it's just the consistency argument that detractors
dislike, but maybe a second look at it would convince them
it's not important.
The suggestions of doing [0, 1, ... 5 ) are, however sheer
insanity :-). Obscure (to all but mathematicians), error
prone, unbalanced braces, rarely needed, etc...
If we just wanted to have another way to type range() it
would be a waste. If we are trying to improve the
readability of the language (especially for newbies)
the [0, 1, ... 5] option (or something close) would be
a good idea.
--
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com
More information about the Python-list
mailing list