I have two large nested dictionaries that I need to merge into a single one:
dict1={
1: {"trait1: 32", "trait2": 43, "trait 3": 98},
2: {"trait1: 38", "trait2": 40, "trait 3": 95},
....
}
and
dict2={
1: {"trait1: 32", "trait2": 43, "trait 4": 54},
2: {"trait1: 38", "trait2": 40, "trait 4": 56},
....
}
and what I'd like to get is this:
dict3={
1: {"trait1: 32", "trait2": 43, "trait 3": 98, "trait 4": 54},
2: {"trait1: 38", "trait2": 40, "trait 3": 95, "trait 4": 56},
....
}
I've tried using:
dict3=dict(list(dict1.items()) + list(dict2.items()))
But it simply copies dict2 for me.
I've also tried looping through the "main" keys like this(I copied the first dictionary to become the final output):
dict3 = dict(dict1)
for key1 in dict3:
for key2 in dict2:
dict3[key1].update({"trait4": dict2[key2]["trait4"]})
But that doesn't work, only every few entries come out as expected in the output. And I'm fairly sure that my approach is wrong on this. Any help is appreciated!