Reinhold Birkenfeld wrote:
Jacob Lee wrote:


About slices:

I agree that Python's slice boundaries (some_list[a:b] being all elements
with a <= index < b) are counterintuitive at first. But this method does
satisfy some handy properties, the first of which being:
 l[:n] + l[n:] = l


And best of all, this is true for _every_ n, at least for the standard
slice implementations...


Secondly, the range() function behaves identically to slices, meaning that
 for i in range(10):
will iterate 10 times, and
 for i in range(len(l)):
will iterate over the indices of the sequence l.

If you had l[a:b] be inclusive on both a and b (instead of inclusive on a
and exclusive on b), you would have to be adding and subtracting one in
all of these examples, leading that much more easily to off-by-one errors.


It would be not so much adding/subtracting if list indices started at 1,
but who on earth would want that? ;)

Reinhold
You certainly do get lots of adding/subtracting even if they start at 1.
For example the length of lst[a : b] would be (a - b + 1).  I certainly
had my share of fencepost problems in Fortran I, II, IV, V ...

--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to