Remove duplicates and original from list

后端 未结 5 943
清酒与你
清酒与你 2020-11-29 12:49

Given a list of strings I want to remove the duplicates and original word.

For example:

lst = [\'a\', \'b\', \'c\', \'c\', \'c\', \'d\', \'e\', \'e\']
         


        
5条回答
  •  生来不讨喜
    2020-11-29 13:30

    lst = ['a', 'b', 'c', 'c', 'c', 'd', 'e', 'e']
    from collections import Counter
    c = Counter(lst)
    print([k for k,v in c.items() if v == 1 ])
    

    collections.Counter will count the occurrences of each element, we keep the elements whose count/value is == 1 with if v == 1

提交回复
热议问题