Lower bounds of lists
greg at cosc.canterbury.ac.nz
Fri Mar 2 04:07:08 CET 2001
Chris Gonnerman wrote:
> Humans count from 1. Hackers count from 0.
In *some* cases, humans count from 0, too. Witness
the large number of people who preferred to regard the
year 2000 as the first year of the 21st century
rather than the last year of the 20th.
(Humans are notoriously inconsistent, too, else those
same people would have called the 20th century the
19th century, but, for some reason known only to
themselves, they didn't.)
Getting back to Python, there's a fair bit of
justification for it when you start looking at slices
of sequences, rather than single elements. There
you get some nice properties such as that x[0:n]
spans the whole of a list with n elements, and
x[a:b] + x[b:c] == x[a:c], and there are exactly
b-a elements in x[a:b], etc.
It takes some experience to get the feel for these
things, but once you do, it will probably start to
feel right to you even if you can't exactly say
why. It's probably because your code will have a lot
less +1s and -1s in it than it would otherwise.
Greg Ewing, Computer Science Dept, University of Canterbury,
Christchurch, New Zealand
To get my email address, please visit my web page:
More information about the Python-list