Delete unique elements from a list

前端 未结 9 1246
[愿得一人]
[愿得一人] 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:02

    Try this:

    >>> a=[1,2,3,3,4,5,6,6,7,8,9,2,0,0]
    >>> a=[i for i in a if a.count(i)>1]
    >>> a
    [2, 3, 3, 6, 6, 2, 0, 0]
    >>> a=[1, 2, 3, 1, 3]
    >>> a=[i for i in a if a.count(i)>1]
    >>> a
    [1, 3, 1, 3]
    >>> a=[1, 2, 3, 4, 5]
    >>> a=[i for i in a if a.count(i)>1]
    a
    []
    

提交回复
热议问题