Coding tips
IndexError: list index out of range in Python: 10 Causes and Fixes (Tested Examples)
Python raises IndexError: list index out of range when you ask for a position that does not exist. Here are 10 real causes, from an empty list and off-by-one bugs to mutating while iterating, with the exact tracebacks from my tests and the fixes that stop the crash.