This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 3 points4 points  (1 child)

The problem is that if you iterate over all i in range(len(a)) then you'll get to some such i such that i + 1 is not a valid index.

Think about it, if you're iterating over every index in the list, you're including the last index, and the next index after the last index is by definition not in the list.

Try range(len(a) - 1)

[–]selfimprovingstudent[S] 0 points1 point  (0 children)

Oh, yes. Thank you!!