0

I have a list with elements occurring more than once, I want to remove multiple occurrence of the same element and keep just one. e.g if list =[1,2,3,3,2,4,4]. I want to remove multiple occurrences so i have just list = [1,2,3,4].

I have a working code but it seems not to totally get the job done especially if the element appears up to 4 times. see my code

def array():
    test = [1,2,3,3,2,4,4]

    print(test)
    for n in test:
        if test.count(n) > 1:
            print(n)
            test.remove(n)
    return test

but it seems not to get the job done, it gives me [1,3,2,3,4]

A.Sasori
  • 385
  • 3
  • 20

0 Answers0