[Tutor] IndexError: list index out of range

John nidianjs at hotmail.com
Tue Nov 22 06:28:56 CET 2011

Hi all,

I have wriiten the following code:

>>>  def survivor(names, step):
     index = step - 1
     next = names
     while len(next)>  1:
         next.remove (next[index])

However when ever i run it i get this error message:

Traceback (most recent call last):
   File "<pyshell#46>", line 1, in<module>
     survivor(["Andrew", "Brenda", "Craig", "Deidre", "Edward",
"Felicity", "Greg", "Harriet"], 4)
   File "<pyshell#45>", line 5, in survivor
     next.remove (next[index])
IndexError: list index out of range

Any ideas about whats causing this error?

Big thanks,

More information about the Tutor mailing list