I have multiple dictionaries:
a = {
"project_1": {
"roles": ["role1"]
},
"project_4": ["foo"]
}
b = {
"project_1": {
"roles": ["role2"]
},
"project_2": {
"roles": ["role4"]
}
}
c = {
"project_5": {
"roles": ["role5"]
}
}
How can I merge these dictionaries to get something like the following:
d = {
"project_1": {
"roles": ["role1","role2"]
},
"project_2": {
"roles": ["role4"]
},
"project_4": ["foo"],
"project_5": {
"roles": ["role5"]
}
}
From the other questions regarding merging of dictionaries, I see that the answers either overwrite the values in a predetermined way, rely on unique keys, or are for a fixed number of dictionaries. I need to retain nested values of similar keys for 2 or more dictionaries.
The constraints of my problem are:
- There are a variable number of keys ("project_X") per dictionary
- The dicts are not of fixed depth but have a max depth