Get a unique list of items that occur more than once in a list

后端 未结 7 1063
深忆病人
深忆病人 2020-12-03 17:51

I have a list of items:

mylist = [\'A\',\'A\',\'B\',\'C\',\'D\',\'E\',\'D\']

I want to return a unique list of items that appear more than

7条回答
  •  北海茫月
    2020-12-03 18:28

    Using a similar approach to others here, heres my attempt:

    from collections import Counter
    
        def return_more_then_one(myList):
             counts = Counter(my_list)
             out_list = [i for i in counts if counts[i]>1]
             return out_list
    

提交回复
热议问题