Diff 2 dicts

My daily Python snippets

·

1 min read

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)