I have an unknown number of dictionaries with an unknown set of keys, e.g.:
d1 = {'job': {'data': {'id': 'string'}}}
d2 = {'job': {'data': {'title': 'string'}}}
d3 = {'job': {'metadata': {'date': 'string'}}}
d4 = {'user': {'id': 'string'}}
I want one combined dictionary that looks like this:
{
'job': {
'data': {
'id': 'string',
'title': 'string'
}
'metadata': {
'date': 'string'
}
},
'user': {
'id': 'string'
}
}
The built-in update
doesn't give me what I want:
>>> combined = {}
>>> combined.update(d1)
>>> combined.update(d2)
>>> combined.update(d3)
>>> combined.update(d4)
>>> combined
{'job': {'metadata': {'date': 'string'}}, 'user': {'id': 'string'}}
This question sounds really close to what I want, but it has the same result:
>>> {**d1, **d2, **d3, **d4}
{'job': {'metadata': {'date': 'string'}}, 'user': {'id': 'string'}}
That question specifically asks for a union, but that doesn't look like a union to me. What am I missing?