Remove duplicates


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/2/4?curriculum_id=4f89dab3d788890003000096#


Traceback (most recent call last):
File "python", line 7, in
File "python", line 2, in remove_duplicates
TypeError: 'int' object is not iterable

it should work, but I don't know what's wrong with my code.

def remove_duplicates(items):
    for i in len(items):
        for j in (i+1,len(items),1):
            if items[j] == items[i]:
                items.remove(items[j])
    return items


#2

It tells you the line and the problem (can't iterate through an int, isn't an iterable value like list or string)


#3

This works perfectly
def remove_duplicates(items):
a=[]
for val in items:
if val not in a:
a.append(val)
return a


#4

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