Suspicious List index out of range


Practice Makes Perfect - remove_duplicates

The error is: "list index is out of range"

It is weird because this code runs fine at Python 3.5.1 Shell.

def remove_duplicates(i_list):
    for i in range(1,tam):
        print("i=%d" %i)
        for j in range(tam_norep):
            print("j=%d" %j)
            if n==no_rep[j]:
        if found==False:
    return no_rep


Maybe, but I find it more likely that you just didn't test the same thing as was tested when the exception occurred in Python2. I don't know which is the case, I just want to point out that you might be making an incorrect assumption here which can be very misleading.

Start by reproducing the problem. What input does your function fail for?
And then compare what it does to what you mean for it to do, find out where it goes wrong.

Feel free to ask if you run into trouble with that, I don't know how far you get with that, just pointing you in the right direction to start you off.


Hi Ionatan!

Unfortunately, in my case, Python does not show what was the input that lead to that error...


Perhaps we can think up some test data ourselves that does that though?
It mentions "list index out of range" which is a pretty big hint about what to look for, we can consider where that might possibly occur.

Can you think of any extreme or special cases that you might have overlooked?


Well pointed... I have just imagined a list with just one element... I think it would fail at the first for loop... I will try it later and let you know! Thanks a lot!


How about less than one element, is that valid input?