array slices in python

Erik Max Francis max at alcyone.com
Mon May 12 21:19:43 EDT 2003


Terry Reedy wrote:

> Think of slice positions as being cursor positions *between* sequence
> items, like the vertical bar cursor of gui editors (as opposed to the
> block on top of char cursors of older fixed pitch display editors).
> Counting the end positions, there are n+1 slice positions for n
> items -- ranging from 0 to n.  If that doesn't do it for you, follow
> the ref in Fernando's response.

Further, Python is not alone in this regard.  Many languages have
realized the value of the closed-open interval for specifying ranges; it
gives you a lot more flexibility.  C++ Standard Library (a.k.a. STL)
containers, for instance, all have ranges that are specified in this
way.

Fortran does things differently, sure, but computer science has moved
on.  Fortran doesn't index arrays from zero, which there are lots of
good computer science reasons to do (i.e., offsets into arrays); the
only pressing reason for indexing from one is because that's the way
some mathematical formulae are written, but that's not a very convincing
argument since it's a trivial substitution to change a [1, n] range to a
[0, n) one.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ I'm the woman whose / Three wishes came true
\__/ Lamya
    Fauxident / http://www.alcyone.com/pyos/fauxident/
 A "faux" ident daemon in Python.




More information about the Python-list mailing list