I'm telling my program to print out line 53 of an output. Is this error telling me that there aren't that many lines and therefore can not print it out?
Try printing 42 instead. It should be the correct answer.
wuub
2009-07-08 15:08:55
+2
A:
If you have a list with 53 items, the last one is thelist[52]
because indexing start at 0.
Alex Martelli
2009-07-08 15:07:15
+1
A:
That's right. 'list index out of range' most likely means you are referring to n-th
element of the list, while the length of the list is smaller than n
.
Grzegorz Oledzki
2009-07-08 15:08:10
+4
A:
Yes,
You are trying to access an element of the list that does not exist.
MyList = ["item1", "item2"]
print MyList[0] # Will work
print MyList[1] # Will Work
print MyList[2] # Will crash.
Have you got an off-by-one error?
kjfletch
2009-07-08 15:08:32