How to change ["a", "a", "a", 2,3,3,2,2] to ['a', 2,3].
def remove_duplicates(x):
list_a = []
for index,i in enumerate(x):
list_a.append(i)
if list_a.count(i) > 1:
list_a.remove(i)
return list_a
print remove_duplicates(["a","a","a",2,3,3,2,2])
#['a',2,3]
Or rather, it seems that the following was good.
def remove_duplicates(x):
y=[]
for i in x:
if i not in y:
y.append(i)
return y
Recommended Posts