python list index - an easy question
ben.usenet at bsb.me.uk
Mon Dec 19 08:48:01 EST 2016
BartC <bc at freeuk.com> writes:
> On 19/12/2016 01:10, Ben Bacarisse wrote:
>> BartC <bc at freeuk.com> writes:
>>> On 18/12/2016 10:59, Paul Götze wrote:
>>>> there is a nice short article by E. W. Dijkstra about why it makes sense
>>>> to start numbering at zero (and exclude the upper given bound) while
>>>> slicing a list. Might give a bit of additional understanding.
>>> (This from somebody who apparently can't use a typewriter?!)
>>> I don't know if the arguments there are that convincing. Both lower
>>> bounds of 0 and 1 are useful; some languages will use 0, some 1, and
>>> some can have any lower bound.
>>> But a strong argument for using 1 is that in real life things are
>>> usually counted from 1 (and measured from 0).
>> The index of an element is a measure, not a count.
> You need to take your C hat off, I think.
It's a computing hat. Indexes are best seen as offsets (i.e. as a
measured distances from some origin or base). It's a model that grew
out of machine addressing and assembler address modes many, many decades
ago -- long before C. C, being a low-level language, obviously borrowed
it, but pretty much all the well-thought out high-level languages have
seen the value in it too, though I'd be interested in hearing about
The main issue -- of using a half open interval for a range -- is
probably less widely agreed upon, though I think it should be. EWD is
correct about this (as about so many things).
More information about the Python-list