range(start,stop)

Mikael Olofsson mikael at isy.liu.se
Mon Feb 14 07:28:43 EST 2000


On 14-Feb-00 Moshe Zadka wrote:
 >  Of course, if you decide lists start at 1, then range should stop at n,
 >  but FORTRAN is (almost) dead and buried ;-)

Well... I know Fortran only by its name. 

Misunderstand me correctly, I want range(m,n) to do what it does. I 
just thought you could give Stephane a better argument. Actually, if 
the shortform range(n) produced the list 1..n, then it would be just 
as logical to have range(0) produce an empty list, and then 
range(len(mylist)) would give a reasonable result, but we would get 
into trouble extending it to range(m,n) in a consistent way. 

I think this should be related to how python addresses lists instead, 
i.e. mylist[0] is the first element in mylist. That, in turn, is logical 
since we use negative numbers to find elements in the end of a list,
which i think is beautiful. We get an unbroken sequence 

  ... , mylist[-2], mylist[-1], mylist[0], mylist[1], ...

This is to me a better reason to let range do what it actually does. If 
we had 

  ... , mylist[-2], mylist[-1], mylist[1], mylist[2], ...,

which is less tasty to me, then perhaps range should do something else.
We would probably have to let range(m,n) produce the list m+1..n instead, 
which I think would raise even more questions.

conservatively y'rs

/Mikael

-----------------------------------------------------------------------
E-Mail:  Mikael Olofsson <mikael at isy.liu.se>
WWW:     http://www.dtr.isy.liu.se/dtr/staff/mikael
Phone:   +46 - (0)13 - 28 1343
Telefax: +46 - (0)13 - 28 1339
Date:    14-Feb-00
Time:    13:01:41

This message was sent by XF-Mail.
-----------------------------------------------------------------------




More information about the Python-list mailing list