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

beliavsky at aol.com beliavsky at aol.com
Thu Apr 21 22:06:41 EDT 2005


Dan Bishop wrote:
> Antoon Pardon wrote:

<snip>

> > 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?

Assuming the + sign means concatenate (as it does for Python lists)
rather than add (as it does for Numeric or Numarray arrays), it would
be

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

since 0 would still be the default indexbase. If the user wanted a
1-based list as a result, he would use an expression such as

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

If + means add, the result would be

([4,6,13] indexbase 0) .

Adding arrays makes sense if they have the same number of elements --
they do not need to have the same indices.

I rarely see problems caused by flexible lower array bounds mentioned
in comp.lang.fortran .




More information about the Python-list mailing list