-1

I have a list,

 mylist=[4, 4, 2, 1, 2]

 my expected output is =[1]

I tried list(set(mylist)) but its not helping

thanks in advance

Pyd
  • 5,668
  • 14
  • 46
  • 94

1 Answers1

1

You may use collections.Counter to get the count of all the items present in the list, then filter it using list comprehension the items having count as 1:

>>> from collections import Counter

>>> mylist=[4, 4, 2, 1, 2]
>>> [k for k, v in Counter(mylist).items() if v==1]
[1]
Moinuddin Quadri
  • 43,657
  • 11
  • 92
  • 117