Skip to main content

Command Palette

Search for a command to run...

Diff 2 dicts

My daily Python snippets

Updated
•1 min read•View as Markdown
Diff 2 dicts
T

Doing unexpectedly geeky stuff.

A case of extracting the diff of 2 dicts in Python

# DICT DIFF EXAMPLE

data = {
    "fee": 1,
    "fi": 2,
    "fo": 3,
    "fum": 4,
}

new_data = {
    "fee": 1,
    "fi": "2",
    "fo": {
         "foo": "bar"
    },
    "fum": 4,
}

diff = {k: v for k, v in new_data.items() if v not in data.values()}
print(diff)