I have tuples nested in a list i.e. [(0,1,2,3,4,5,6,7), (etc)].
I'm trying to return the tuples that are matching at index 0 & 1, and 3 to 5 (and to keep the ordering of the data inside the tuple)
So with the code below I'm trying to remove the duplicates, then with the result I'm comparing this to the original list to identify the duplicates removed:
seen = set()
seen_add = seen.add
newL = []
for a in myList:
if a[:2] not in seen and not seen_add(a[:2]):
if a[3:6] not in seen and not seen_add(a[3:6]):
newL.append(a)
result = list(set(myList) - set(newL))
for i in result: print i
But the first part removes a tuple that doesn't even have a duplicate.
N.B. The code for removing the first two elements came from here (by Martijn Pieters): Removing Duplicates from Nested List Based on First 2 Elements; but removing additional elements resulted in the aforementioned 'error'.
To return the duplicates (this code follows the answer by @unutbu)
for i in result:
for e in newL:
if i[:2]==e[:2]:
if i[3:6]==e[3:6]:
print e, i