Question

Line    , P, H, #, SET
0x53e9e0, 0, 0, 1, 55
0x53ea18, 0, 0, 2, 55
0x53ea50, 0, 0, 3, 55
0x53ea18, 0, 1, 4, 55
0x53ea88, 0, 0, 5, 55
0x53eac0, 1, 0, 6, 55
0x53ea18, 0, 1, 7, 55
0x53eaf8, 0, 0, 8, 55
0x53eb30, 1, 0, 9, 55
0x53eb30, 0, 1, 10, 55
0x53eb68, 0, 0, 11, 55
0x53eba0, 1, 0, 12, 55
0x53ebd8, 1, 0, 13, 55
0x53ec10, 0, 0, 14, 55
0x53ec48, 1, 0, 15, 55
0x53ec48, 1, 1, 16, 55
0x53ec80, 0, 0, 17, 55
0x53ecb8, 0, 0, 18, 55
0x53ecf0, 1, 0, 19, 55
0x53ecf0, 0, 1, 20, 55
0x53ed28, 1, 0, 21, 55
0x53e9e0, 1, 0, 22, 55
0x53e9e0, 0, 1, 23, 55
0x53e9e0, 1, 1, 24, 55

For every set ranging from 0 to 1024 and occurring in any order (above I printed only the first 25 of the 55th set). I want to see for every line, with P==1 before it and having a H==1 after it. I want to know how many runs have gone through if it is less than 16.

For example: Consider line:0x53e9e0 in physical line 2 has P and H as 0. In line the last but third line (line 23), 0x53e9e0 reoccurs but more than 16 runs have gone through (so it is considered as a new line) However, line 23 and 24 have a difference of 1.

There are multiple such lines with a difference of 1-16. I want to find all those lines on a per set basis.

Was it helpful?

Solution

lines = """0x53e9e0, 0, 0, 1, 55
0x53ea18, 0, 0, 2, 55
0x53ea50, 0, 0, 3, 55
0x53ea18, 0, 1, 4, 55
0x53ea88, 0, 0, 5, 55
0x53eac0, 1, 0, 6, 55
0x53ea18, 0, 1, 7, 55
0x53eaf8, 0, 0, 8, 55
0x53eb30, 1, 0, 9, 55
0x53eb30, 0, 1, 10, 55
0x53eb68, 0, 0, 11, 55
0x53eba0, 1, 0, 12, 55
0x53ebd8, 1, 0, 13, 55
0x53ec10, 0, 0, 14, 55
0x53ec48, 1, 0, 15, 55
0x53ec48, 1, 1, 16, 55
0x53ec80, 0, 0, 17, 55
0x53ecb8, 0, 0, 18, 55
0x53ecf0, 1, 0, 19, 55
0x53ecf0, 0, 1, 20, 55
0x53ed28, 1, 0, 21, 55
0x53e9e0, 1, 0, 22, 55
0x53e9e0, 0, 1, 23, 55
0x53e9e0, 1, 1, 24, 55"""

last_seen = {}
for i, line in enumerate(lines.split('\n')):
    id = line.split(',')[0]
    if id in last_seen:
        last_i = last_seen[id]
        delta = i - last_i
        if delta <= 16:
            print("last seen {} at {}, {} lines ago.".format(id, last_i, delta))
    last_seen[id] = i

Output:

last seen 0x53ea18 at 1, 2 lines ago.
last seen 0x53ea18 at 3, 3 lines ago.
last seen 0x53eb30 at 8, 1 lines ago.
last seen 0x53ec48 at 14, 1 lines ago.
last seen 0x53ecf0 at 18, 1 lines ago.
last seen 0x53e9e0 at 21, 1 lines ago.
last seen 0x53e9e0 at 22, 1 lines ago.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top