I am a beginner learning Python and was trying to remove duplicates from list while using any (Trying to learn any()
and all()
).
def remove_duplicates(x):
l=0
for i,item in enumerate(x):
if any(l==item for l in x)==True:
print (i,item)
x=del x[i]
return(x)
x=[1,2,3,1]
print (remove_duplicates(x))
I am getting the following result.
0 1
1 3
[2, 1]
Instead of [2,3,1].