Suppose I have 2 list of dictionaries of the form:
a = [{'count': 10, 'name': 'ABC', 'dates':{'2018':1,'2019':4,'2020':5}}, {'count': 5, 'name': 'XYZ', 'dates':{'2018':2,'2019':4,'2020':3}}]
b = [{'count': 5, 'name': 'ABC', 'dates':{'2018':3,'2019':1,'2020':3}}, {'count': 3, 'name': 'XYZ', 'dates':{'2018':3,'2019':5,'2020':11}}]
Now i want to merge dictionary b into a such that each number corresponding to same date in a dictionary are added up and I get something of the following sort:
a = [{'count': 15, 'name': 'ABC', 'dates':{'2018':4,'2019':5,'2020':8}}, {'count': 8, 'name': 'XYZ', 'dates':{'2018':5,'2019':9,'2020':14}}]
How can this be achieved? I tried doing it through for loops, but it is turning out very complex. Is there a pythonic way of doing it?