Why Python does *SLICING* the way it does??

Dan Bishop danb_83 at yahoo.com
Thu Apr 21 14:47:01 EDT 2005


Antoon Pardon wrote:
> Op 2005-04-21, Steve Holden schreef <steve at holdenweb.com>:
> > beliavsky at aol.com wrote:
...
> >> Along the same lines, I think the REQUIREMENT that x[0] rather
than
> >> x[1] be the first element of list x is a mistake. At least the
> >> programmer should have a choice, as in Fortran or VBA. In C
starting at
> >> 0 may be justified because of the connection between array
subscripting
> >> and pointer arithmetic, but Python is a higher-level language
where
> >> such considerations are less relevant.
> >>
> > But Pythonicity required that there should be one obvious way to do

> > something. How obvious is having two ways?
>
> How obvious is that lists can be any length? Do you consider it
> an unbounded number of ways, that lists can be any length?
>
> Like users have a choice in how long they make a list, they
> should have a choice where the indexes start. (And that
> shouldn't be limited to 0 and 1).

Suppose you could.  Then what should

([3, 1, 4] indexbase 0) + ([1, 5, 9] indexbase 4)

equal?

> That you are forced to use zero-based structures, while the
> problem space you are working on uses one-based structures
> is a far bigger stumbling block where you continually have
> to be aware that the indexes in your program are one off
> from the indexes the problem is expressed in.

Name a problem space that inherently requires arrays to be 1-based
rather than 0-based.




More information about the Python-list mailing list