Skip to content

Instantly share code, notes, and snippets.

@bast
Created March 24, 2021 09:30
Show Gist options
  • Save bast/85a5c2eda5501fe915faaa84846abe29 to your computer and use it in GitHub Desktop.
Save bast/85a5c2eda5501fe915faaa84846abe29 to your computer and use it in GitHub Desktop.
Comparing dictionaries in Python
# https://github.com/seperman/deepdiff
from deepdiff import DeepDiff
d1 = {"something": 1, "another": 2, "yet another": 3}
d2 = {"something": 2, "another": 2, "yet another": 3}
difference = DeepDiff(d1, d2, ignore_order=True)
print(difference)
d1 = {"something": 1, "another": 2, "yet another": 3}
d2 = {"something": 1, "yet another": 3, "another": 2}
difference = DeepDiff(d1, d2, ignore_order=True)
print(difference)
d1 = {"something": 1, "another": 2, "yet another": 3, 'subdict': {'a': 2, 'b': 3}}
d2 = {"something": 1, "another": 2, "yet another": 3, 'subdict': {'a': 3, 'b': 3}}
difference = DeepDiff(d1, d2, ignore_order=True)
print(difference)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment