I created a dictionary of lists using:
names = defaultdict(list)
I am reading a line from the text file, splitting it into 3 columns. I am making the first column of the line as key and other two columns as the values in a list. I used the following code segment as following:
with open('f.txt') as f:
lines = [l.split() for l in f.readlines() if l.strip()]
for l in lines:
names[l[0]].append([l[1],l[2]])
I have the text files like this:
00:12:34:23:45:67 134 123.456
45:34:23:45:44:23 133 345.123
3f:32:dr:45:34:r5 133 212.345
00:12:34:23:45:67 134 555.555
00:12:34:23:45:67 136 555.556
00:12:34:23:45:67 134 555.560
If i run my program to output key:value pairs, the output is:
00:12:34:23:45:67 [['134', '123.456'], ['134', '555.555'], ['136', '555.556'], ['134', '555.560']]
45:34:23:45:44:23 [['133', '345.123']]
3f:32:dr:45:34:r5 [['133', '212.345']]
How can I access the individual elements of the list? For example, in this output, I want to count number of 133, 134, 135, 136 of each key and the time difference between each type. For example, for the key 00:12:34:23:45:67, there are 3 134’s, 1 136. The time difference between highest of and lowest of 134’s for that key is 555.560-123.456. I want this result for all 133,134,135,136 types. I am struggling for this problem from many days. please help. Much appreciated.
It seems like a better data structure is in order here…
Now, to get the counts and differences from max/min:
Output: