1def dict_compare(d1, d2):
2 d1_keys = set(d1.keys())
3 d2_keys = set(d2.keys())
4 shared_keys = d1_keys.intersection(d2_keys)
5 added = d1_keys - d2_keys
6 removed = d2_keys - d1_keys
7 modified = {o : (d1[o], d2[o]) for o in shared_keys if d1[o] != d2[o]}
8 same = set(o for o in shared_keys if d1[o] == d2[o])
9 return added, removed, modified, same
10
11x = dict(a=1, b=2)
12y = dict(a=2, b=2)
13added, removed, modified, same = dict_compare(x, y)
1In [1]: from deepdiff import DeepDiff
2
3In [2]: a = {
4 ...: 'number': 1,
5 ...: 'list': ['one', 'two']
6 ...: }
7
8In [3]: b = {
9 ...: 'list': ['one', 'two'],
10 ...: 'number': 2
11 ...: }
12
13In [4]: diff = DeepDiff(a, b)
14
15In [5]: diff
16Out[5]: {'values_changed': {"root['number']": {'new_value': 2, 'old_value': 1}}}
17