Getting the repeated count data from tuple list item 1 which holds the patient counter data
...data[1]
. With below down samples i dont need to consider the duplicates on data[0]
or data[2]
import itertools
def getDuplicateinTuple(dataInput):
seen={}
return [seen.setdefault(t[0], t) for t in dataInput if t[0] not in seen]
data=[('2013 Jul 5 06:56:07:', 'PATIENT:COUNTER1'),
('2013 Jul 5 06:56:07:', 'PATIENT:COUNTER2'),
('2013 Jul 5 06:56:07:', 'PATIENT:COUNTER3'),
('2013 Jul 5 06:56:07:', 'PATIENT:COUNTER4'),
('2013 Jul 5 06:57:11:', 'PATIENT:COUNTER1'),
('2013 Jul 5 06:56:11:', 'PATIENT:COUNTER5')]
data1=[('2013 Jul 5 04:26:40:', 'PATIENT:COUNTER1', 'COUNTER INFO: : 500 '),
('2013 Jul 5 04:26:40:', 'PATIENT:COUNTER2', 'COUNTER INFO: : 500 '),
('2013 Jul 5 04:26:40:', 'PATIENT:COUNTER3', 'COUNTER INFO: : 100 '),
('2013 Jul 5 04:26:40:', 'PATIENT:COUNTER4', 'COUNTER INFO: : 100 ')]
s=getDuplicateinTuple(data)
print s
s1=getDuplicateinTuple(data1)
print s1
and the expected output is :
[('2013 Jul 5 06:56:07:', 'PATIENT:COUNTER1'), ('2013 Jul 5 06:57:11:', 'PATIENT:COUNTER1')]
and actual output is
[('2013 Jul 5 06:56:07:', 'PATIENT:COUNTER1'), ('2013 Jul 5 06:57:11:', 'PATIENT:COUNTER1'), ('2013 Jul 5 06:56:11:', 'PATIENT:COUNTER5')]
on same if I give a non duplicate output as in data1
expected output :
[]
but current output:
[('2013 Jul 5 04:26:40:', 'PATIENT:COUNTER1', 'COUNTER INFO: : 500 ')]
Just by comparing the list this can be achieved. What is the better and suggested way to make achieve this?
I saw some nice stack post on this regards: Find and list duplicates in a list?