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
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]