-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
  • 6,017
  • 18
  • 52
  • 109

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
  • 46,825
  • 13
  • 96
  • 126