python - How to get non-repeated elements in a list -


i want non repeating elements in list. here is.

a=[1, 2, 3, 2, 5, 1] 

required output: [3,5]

set() gives [1, 2, 3, 5]

please let me know achieve task.

you can use count() method list object count equal 1:

>>> a=[1, 2, 3, 2, 5, 1] >>> unique=[i in if a.count(i)==1] >>> unique [3, 5] 


alternatively counter() class collections module can used:

a = [1, 2, 3, 2, 5, 1]  c = counter(a)  print [key key, count in c.iteritems() if count==1] 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -