# python for loop

Carl Banks pavlovevidence at gmail.com
Thu Apr 2 08:47:00 CEST 2009

```On Apr 1, 9:23 pm, John O'Hagan <resea... at johnohagan.com> wrote:
> Despite being thoroughly acclimatised to zero-based indexing and having no
> wish to change it, I'm starting to see the OP's point.
>
> Many of the arguments presented in this thread in favour of zero-based
> indexing have rather been arguments for half-open intervals, which I don't
> think are in dispute. We all want these to be true:
>
> foo[:n] is the first n items of the sequence foo
> foo[:n] + foo[n:] == foo
> len(foo[n:m]) == m-n
> (foo[n:n]) is an empty sequence
> etc.
>
> and they are true with 0-based indexing if we exclude the last number, or
> equally with 1-based indexing if we exclude the first.

Unless I'm missing something, wouldn't that mean:

range(0,10) -> [1,2,3,4,5,6,7,8,9,10]

Even though it's theoretically just another way to line up the open
interval, as practical matter it's going to be a lot more confusing.
Of course you could exclude the last number with one-based indexing
also, but that would be confusing too, since you would have to use
something like range(1,len(x)+1) to iterate over the items of x.

Given that, I'm going to disagree that a half-open interval is
desirable in the case of one-based indexing.

Furthermore, I know of no languages that use both one-based indexing
and half-open intervals.  Do you know of any?

> Beyond being part of a conventionally-ordered set of keys, what can an
> ordinality of zero actually mean? (That's a sincere question.)

I think people were being facetious.  To me the first item in the list
is x[0]--ordinal does not match cardinal.  However, I don't use
ordinals much when talking about list items; I'll say item 2, not
third item.

Carl Banks

```