What is the pythonic way to properly merge dictionaries in a list Given list of dictionaries:
[
{
"introduced_at": "28.12.2000",
"item": "Pizza",
"item_price": [
{
"date": "01.01.2011",
"details": [
{"price": 1000, "changed_by": "Dieter"},
{"price": 900, "changed_by": "Nina"},
],
}
],
},
{
"introduced_at": "28.12.2000",
"item": "Pizza",
"item_price": [
{
"date": "01.01.2012",
"details": [
{"price": 1050, "changed_by": "Dieter"},
{"price": 900, "changed_by": "Nina"},
],
}
],
},
]
expected:
{
"price_dev": [
{
"introduced_at": "28.12.2000",
"item": "Pizza",
"item_price": [
{
"date": "01.01.2011",
"details": [
{"price": 1000, "changed_by": "Dieter"},
{"price": 900, "changed_by": "Nina"},
],
},
{
"date": "01.01.2012",
"details": [
{"price": 1050, "changed_by": "Dieter"}
],
},
],
}
]
}
The key item and its value in combination with their introduced_at can be found twice in the list so they may be used as unique idenfitiers to merge the entries on. As for the details, since date are both different, they should be displayed seperately. Duplicates as seen in changed_by Nina should be disregarded.