[Tutor] referring to list elements

Kirby Urner urnerk@qwest.net
Sun, 14 Apr 2002 16:47:36 -0700


At 11:44 PM 4/11/2002 -0500, Christopher Smith wrote:
>Can someone educated in comp sci tell me whether you really
>refer to the elements of a list, when speaking, as zero-eth,
>one-eth, two-eth, etc..., as described in the How to Think book?
>What do you do when you get to the fifth element: do you call
>it the four-eth element?  If you refer to them in the natural
>linguistic sense as '1st', '2nd', etc..., are you always
>doing a little mental gymnastics to remember that the index
>is one less than the actual element position in the ordinal
>sense?
>
>['1st','2nd','3rd','4th','5th'] #indices [0,1,2,3,4]
>
>/c

Yeah, we say the index of the Nth element of a list in N-1.

It's correct to say the first element has index 0, just
as we say the length of a list of N elements -- as in
len(thelist) -- is N, not N-1.  But the indices of such
a list range from 0 to N-1.

And yes, you're always doing a little mental gymnastics
to remember that the index of the Nth element is N-1.
But that's not so bad, really.

Kirby




>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor