Re: New to python and list index out of range!

Posted 27 August 2015 - 07:51 AM

The first step in figuring out a problem like this is to figure out exactly what's breaking. One easy way to do this is to insert print statements to display the values of the interesting variables at various points in the program so you can see them evolve. For example, in this case I'd be interested in knowing the local values of alist and ed

You can also use a debugger, like pdb. This is what I use on the job. Look it up in the python documentation if you're interested, it lets you step through the code and examine the state of the machine in detail. Very cool once you get the hang of it.

Re: New to python and list index out of range!

Posted 27 August 2015 - 03:44 PM

For sure you will get a problem in line 8 with alist[ed], as ed = len(alist).
len(alist) = 9, but valid list index is only from 0 to 8
As far as I can see, a similar problem may occour in line 7 with alist[i].