[Python-bugs-list] [ python-Feature Requests-736470 ] An alternative to "range"

SourceForge.net noreply@sourceforge.net
Thu, 15 May 2003 06:05:32 -0700


Feature Requests item #736470, was opened at 2003-05-12 14:44
Message generated for change (Comment added) made by alexanro
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=736470&group_id=5470

Category: Python Interpreter Core
Group: None
Status: Closed
Resolution: Wont Fix
Priority: 5
Submitted By: Alexander Rødseth (alexanro)
Assigned to: Nobody/Anonymous (nobody)
Summary: An alternative to "range"

Initial Comment:
As far as I know, range() has often beeing critizised
for beeing ugly, particualarly in connection with
for-loops. In my eyes, it's also a bit inconsistent
that range(x, y) creates a list from x to y, but not
including y.

My suggestion is to include a pascal-like way of
creating lists, with ".."  like this:

l = [x..y]

this would be equal to today's:

l = range(x, y + 1)

(which I think is quite ugly)

Here's another example of how it would look:

for i in [1..3]:
   print i

Output:
1
2
3

This could be particularly useful for beginners, and is
quite pythonic, as I see it. It's clear and consise,
and would be a welcome addition to the python language.
In connection with ie. string-manipulation, it would
clear up things a great deal.


----------------------------------------------------------------------

>Comment By: Alexander Rødseth (alexanro)
Date: 2003-05-15 13:05

Message:
Logged In: YES 
user_id=679374

How about the math-like notation [1..2) then, in order to
keep the half-open intervals? In my point of view, this
would have much of the same clarifying effect.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-05-12 17:17

Message:
Logged In: YES 
user_id=80475

A language should consistently use either half-open 
intervals or closed-intervals but *never* mix the two.  The 
same applies to whether lists should be indexed starting 
at zero or one.  Python consistently applies half-open 
intervals and zero based indexing; any contamination of 
these unifying themes would be a mistake.

The alternatives each have their advantages.  With closed 
intervals, you accurately highlight how easy it is to see the 
end-point.  On the plus side for half-open intervals, it is 
easier to see how many elements are in the loop (e-b 
versus e-b+1) and it is easier to link successive intervals 
because of invariants like a[:n] + a[n:] = a[:].






----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=736470&group_id=5470