473,473 Members | 2,169 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Q's: pythonD and range(1,12)

I've very new to python, and am currently toying with pythonD. Could
someone please explain the rationale behind python designers' thinking
in deciding the function "range(1,12)" should return the sequence 1 to
11 rather than the more intuitively-useful 1 to 12??

After downloading the substantial distribution .zip file, I'm intrigued
to find it includes 3 files of identical size and creation date, differing
apparently only in name (python, python2.4 and python24.exe) and each of
exactly 2,597,888 bytes. What possible purpose could be served by such
triplication that couldn't more efficiently be done by other means?

Naive but curious minds wish to know!
--
John Savage (my news address is not valid for email)

Mar 14 '06 #1
3 1224
John Savage wrote:
Could someone please explain the rationale behind python designers' thinking
in deciding the function "range(1,12)" should return the sequence 1 to
11 rather than the more intuitively-useful 1 to 12?? Essentially, it has to do with the decision to have range(5) mean the
list [0, 1, 2, 3, 4] (which is five elements long). Any choice will
please some and offend others; this one in Python has no chance of
changing.
After downloading the substantial distribution .zip file, I'm intrigued
to find it includes 3 files of identical size and creation date, differing
apparently only in name (python, python2.4 and python24.exe) and each of
exactly 2,597,888 bytes. What possible purpose could be served by such
triplication that couldn't more efficiently be done by other means?


You obviously know what and where PythonD came from, but we don't.
--
-Scott David Daniels
sc***********@acm.org
Mar 14 '06 #2
John Savage wrote:
Could
someone please explain the rationale behind python designers' thinking
in deciding the function "range(1,12)" should return the sequence 1 to
11 rather than the more intuitively-useful 1 to 12??


There are several ways to do this, closed intervals, half-open
intervals, zero indexed, indexed from one, etc. Each way has its own
strengths and weaknesses. Guido chose the one he liked best and
applied the concept consistently throughout the language (slicing,
etc). His choice has some nice properties such as len(range(n))==n and
range(0,i)+range(i,n)==range(n).

The downside of the half-open interval approach is that it can be
confusing when counting backwards: range(n-1, -1, -1). Accordingly,
the builtin reversed() function was introduced so you could write this
in a more intuitive and readable manner: list(reversed(range(n))).

Some of this is a matter of taste and a matter of what you're used to
using, so the answer to what is the "more intuitively-useful" varies
depending on who is answering the question.
Raymond

Mar 14 '06 #3
On Mon, 13 Mar 2006 17:24:31 -0800, Raymond Hettinger wrote:
John Savage wrote:
Could
someone please explain the rationale behind python designers' thinking
in deciding the function "range(1,12)" should return the sequence 1 to
11 rather than the more intuitively-useful 1 to 12??


There are several ways to do this, closed intervals, half-open
intervals, zero indexed, indexed from one, etc. Each way has its own
strengths and weaknesses. Guido chose the one he liked best and
applied the concept consistently throughout the language (slicing,
etc). His choice has some nice properties such as len(range(n))==n and
range(0,i)+range(i,n)==range(n).

The downside of the half-open interval approach is that it can be
confusing when counting backwards: range(n-1, -1, -1). Accordingly,
the builtin reversed() function was introduced so you could write this
in a more intuitive and readable manner: list(reversed(range(n))).

Some of this is a matter of taste and a matter of what you're used to
using, so the answer to what is the "more intuitively-useful" varies
depending on who is answering the question.


It is true that *some* of this is just a matter of taste, but more
importantly, *much* of this is a matter of objective superiority.

See, for example:

http://lists.canonical.org/pipermail...ch/000757.html
http://www.jaggersoft.com/pubs/HowTo...pen%20Interval

This thread discusses why a closed interval is better:

http://mail.python.org/pipermail/edu...il/003747.html

As near as I can tell from reading it, the sole reason a closed interval
is better is that in common English phrases "x to y" usually (but not
always) means the closed interval including both x and y.

A very common error in programming is the so-called fencepost error.
Half-open intervals help avoid them, while closed intervals tend to
result in this bug.

http://en.wikipedia.org/wiki/Fencepost_error

In other words, while the choice of half-open intervals is partly a matter
of taste, Guido is no dummy. Most of the time, his taste is influenced by
practical matters, and this is one of those times. Half-open intervals
will naturally help you avoid bugs.
--
Steven.

Mar 14 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Xah Lee | last post by:
Today we'll be writing a function called Range. The Perl documentation is as follows. Perl & Python & Java Solutions will be posted in 48 hours. This is Perl-Python a-day. See...
4
by: IMS.Rushikesh | last post by:
Hi All, I am trying to execute below code but it gives me an COMException ///// Code Start //// public string GetName(Excel.Range range) { try { if (range.Name != null)
5
by: Chris | last post by:
Hey all. Anyone who is familiar with Python programming knows that you can have code like this: list = This code puts all the items processed by the for loop in a list plus 1. Is there a way...
1
by: John Savage | last post by:
I'm finding that many times when I inadvertently code an endless loop in pythonD code, on MSDOS, execution cannot be interrupted by ctrl-C and I am forced to reboot and this is rapidly loses its...
3
by: toton | last post by:
Hi, I want ro iterate over a few container class within a range specified, instead of begin & end. How to construct a range class, which takes start & end, and iteration is available within that...
85
by: Russ | last post by:
Every Python programmer gets this message occasionally: IndexError: list index out of range The message tells you where the error occurred, but it doesn't tell you what the range and the...
3
by: caddit | last post by:
Hello. There has been some confusion as to the current version of the python programming language available for DOS. This is partially due to incorrect information kept on python.org, that...
2
by: John Simeon | last post by:
Hi there. I had an old computer at my disposal and decided to put it to use by setting up a nostalgia project with DOS and Windows for Workgroups 3.11. Now that all of you are back from laughing...
0
by: iain654 | last post by:
I have finally worked out how to automatically send a range of cells in the body of an email using Outlook but it is very clumsy and I have to build up the email using the limit of line...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.