2

I am trying make a remove duplicate function in python but for some reason it gives strange output. note that I do wish to use list(set(some_list)). I just want to know why the following gives such output.

def removeD(A):
    for num in A:
        if A.count(num) > 1:
            A.remove(num)
    return A

A = [0,0,0,1,1,1,1,2,2,2,2,2]
print (removeD(A))

outputs:

[0, 1, 1, 2, 2, 2]

0 Answers0