I have 2 lists of dictionaries:
dict1 = [{"a":1, "b":2, "c":1295}, {"a":2, "b":5, "c":6274}, {"a":3, "b":1, "c":5337}]
and
dict2 = `[{"a":1, "b":2, "d":1884}, {"a":2, "b":5, "d":2049}, {"a":3, "b":3, "d":1086}]
The first list of dicts has the keys "a"
, "b"
and "c"
, while the second list has keys "a"
, "b"
and "d"
.
I want to create a list of merged dicts having all 4 keys. Only the dicts with equal values for "a"
and "b"
need to be merged.
The expected result looks like this:
[{"a":1, "b":2, "c":1295, "d":1884}, {"a":2, "b":5, "c":6274, "d":2049}]
I am looking for a Pythonic way of doing this.