Delete unique elements from a list

前端 未结 9 1250
[愿得一人]
[愿得一人] 2020-12-10 09:20

I faced some problem with solving the next problem:

We have a list of elements (integers), and we should return a list consisting of only the non-unique elements in

9条回答
  •  难免孤独
    2020-12-10 10:16

    Would it not be easier to generate a new list?

    def unique_list(lst):
        new_list = []
        for value in lst:
            if value not in new_list:
                new_list.append(value)
        return new_list
    
    lst = [1,2,3,1,4,5,1,6,2,3,7,8,9]
    print(unique_list(lst))
    

    Prints [1,2,3,4,5,6,7,8,9]

提交回复
热议问题