def dict_compare(d1, d2):
d1_keys = set(d1.keys())<EOL>d2_keys = set(d2.keys())<EOL>intersect_keys = d1_keys.intersection(d2_keys)<EOL>added = d1_keys - d2_keys<EOL>removed = d2_keys - d1_keys<EOL>modified = {o: (d1[o], d2[o]) for o in intersect_keys if d1[o] != d2[o]}<EOL>same = set(o for o in intersect_keys if d1[o] == d2[o])<EOL>return added, removed, modified, same<EOL>
Comparing two dictionaries.

    Note: https://stackoverflow.com/questions/4527942/comparing-two-dictionaries-in-python