I have two defaultdict
:
defaultdict(<type 'list'>, {'a': ['OS', 'sys', 'procs'], 'b': ['OS', 'sys']})
defaultdict(<type 'list'>, {'a': ['OS', 'sys'], 'b': ['OS']})
How do I compare these two to get the count of values missing from each one.
For example I should get two values are missing from second defaultdict for key 'a'
and one missing from 'b'
.
If you just want the total number missing from the second default dict, you can iterate through the first dict and look at the set difference to figure out how many more things are in A relative to B.
If you define the dicts like this:
a = defaultdict(list, {'a': ['OS', 'sys', 'procs'], 'b': ['OS', 'sys']})
b = defaultdict(list, {'a': ['OS', 'sys'], 'b': ['OS']})
This will tell you how many are missing from dict B:
total_missing_inB = 0
for i in a:
diff = set(a[i]) - set(b[i])
total_missing_inB += len(diff)
And this will tell you how many are missing from dict A
total_missing_inA = 0
for i in b:
diff = set(b[i]) - set(a[i])
total_missing_inA += len(diff)