You can use this as a base (instead of treating '11.24' as a float, I guess you want to adapt for hours/minutes or minutes/seconds)... you can effectively union and subtract matching keys using a defaultdict
.
As long as you can get your data into a format like this:
f1 = [
[11.24, 1],
[11.26, 2],
[11.27, 3],
[11.29, 5],
[11.30, 6]
]
f2 = [
[11.25, 1],
[11.26, 3],
[11.27, 4],
[11.31, 6],
[11.32, 7],
[11.33, 8]
]
Then:
from collections import defaultdict
from itertools import chain
dd = defaultdict(float)
for k, v in chain(
((b, a) for a, b in f1),
((b, -a) for a, b in f2)): # negate a
dd[k] += v
Results in:
{1: -0.009999999999999787,
2: 11.26,
3: 0.009999999999999787,
4: -11.27,
5: 11.29,
6: -0.009999999999999787,
7: -11.32,
8: -11.33}
For matches only
matches = dict( (k, v) for v, k in f1 )
d2 = dict( (k, v) for v, k in f2 )
for k, v in matches.items():
try:
matches[k] = v - d2[k]
except KeyError as e:
del matches[k]
print matches
# {1: -0.009999999999999787, 3: 0.009999999999999787, 6: -0.009999999999999787}