While loop error

sam westernsam at hotmail.com
Fri Feb 1 11:14:25 EST 2002


len() gives you the length of a list (or string etc)
the following list has a length of three

list = [1,2,3]
#therefore 
len(list) == 3

you reference list starting at zero
therefore

list[0] == 1
list[1] == 2
list[2] == 3
list[3] ==

index out of range exception ...

to make you code work make list_length = len(list) -1

this is the same with every languages implemetation of list or array
that i have ever seen. You just gotta get used to it.

sam



More information about the Python-list mailing list