values = {}
for t in tups:
a,b,c,d = t
if a not in values:
values[a] = (1, t)
else:
count, tup = values[a]
values[a] = (count+1, t)
unique_tups = map(lambda v: v[1],
filter(lambda k: k[0] == 1, values.values()))
I am using a dictionary to store a
values and the tuples that have that a
value. The value at that key is a tuple of (count, tuple)
where count
is the number of times that a
has been seen.
At the end, I filter the values
dictionary for only those a
values where the count
is 1, i.e. they are unique. Then I map that list to return only those tuples, since the count
value will be 1.
Now, unique_tups
is a list of all those tuples with unique a
's.
Updated after receiving feedback from commenters, thanks!