Created
August 20, 2021 11:36
-
-
Save juandesant/1f9fd3e61b056dba3a40b59d997e5ed9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dict_diff(dict_a, dict_b, show_value_diff=True): | |
result = {} | |
result['added'] = {k: dict_b[k] for k in set(dict_b) - set(dict_a)} | |
result['removed'] = {k: dict_a[k] for k in set(dict_a) - set(dict_b)} | |
if show_value_diff: | |
common_keys = set(first_dict) & set(second_dict) | |
result['value_diffs'] = { | |
k:(dict_a[k], dict_b[k]) | |
for k in common_keys | |
if dict_a[k] != dict_b[k] | |
} | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment