Reputation: 605
I am simply trying to remove both entries if one is duplicate...for example if the array is
(9,1,2,2,3,4)...I need to output (9,1,3,4)
Most of the pandas methods like drop_duplicates() keep either the top or bottom entry. My data has always double duplicates and even number of elements always!
So example (1,4,6,7,3,3,0,0) output should be 1,4,6,7
Upvotes: 1
Views: 192
Reputation: 2726
You have tuples there not arrays (lists in python use []
). If you want to keep it as tuples you could do:
# if you need a new tuple
a = (1,4,6,7,3,3,0,0)
b = ()
for i in a:
if a.count(i) == 1:
b = b + (i,)
print b # (1, 4, 6, 7)
You could even do it in one line:
# if you want to replace the original tuple
a = tuple(i for i in a if a.count(i) == 1)
print a # (1, 4, 6, 7)
Upvotes: 0
Reputation: 18848
import collections
a = (1,4,6,7,3,3,0,0)
a = [x for x,y in collections.Counter(a).items() if y == 1]
Upvotes: 1