Remove Duplicates


Traceback (most recent call last):
File "python", line 13, in
File "python", line 7, in remove_duplicates
IndexError: list index out of range

Can some one please help me with why my code does not work? :slight_smile:

def remove_duplicates(x):
    lst= x
    count =1
    for n in lst:
        if count< len(lst):
            for m in range(count, len(lst)):
                if n==lst[m]:
    print lst
    return lst
a= [1, 1, 2, 2]


Have you had a look at your error message? It's telling you what and where

Do note that changing the size of your list will affect loops currently iterating through it.
You'll have an easier time creating a new list with only the values to keep


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.