How do I find the duplicates in a list and create another list with them?

前端 未结 30 1591
梦谈多话
梦谈多话 2020-11-22 00:56

How can I find the duplicates in a Python list and create another list of the duplicates? The list only contains integers.

30条回答
  •  离开以前
    2020-11-22 01:24

    When using toolz:

    from toolz import frequencies, valfilter
    
    a = [1,2,2,3,4,5,4]
    >>> list(valfilter(lambda count: count > 1, frequencies(a)).keys())
    [2,4] 
    

提交回复
热议问题