I have a scenario where I have three dictionaries which I want merge into one but the condition is while I compare the three dictionaries with key name
if there are duplicates need to remove them.
Here is what I have tried :
dict1= {'d1': [{'name': 'app1', 'id': 7134}, {'name': 'app2', 'id': 242}, {'name': 'yest app', 'id': 67},{'name': 'abc jam app', 'id': 6098}]}
dict2= {'d2': [{'name': 'app1 ', 'id': 30}, {'name': 'app2', 'id': 82}, {'name': 'yest app', 'id': 17}]}
dict3= {'d3': [{'name': 'app1', 'id': 70}, {'name': 'app2', 'id': 2582},{'name': 'availabla2z', 'id': 6667}]}
dict2 = {i:j for i,j in dict2.items() if i not in dict1}
dict3 = {i:j for i,j in dict3.items() if i not in dict2}
But the same do not give results also I am not sure how to compare three dicts for that matter.
and since if you look at the data dict1
is having an element 'name': 'app1'
where as the same element is there in dict2
like this 'name': 'app1 '
(with a space) not sure how to format this as well and get a final dict like below as result.
{'final': [{'name': 'app1 ', 'id': 30}, {'name': 'app2', 'id': 82}, {'name': 'yest app', 'id': 17},{'name': 'abc jam app', 'id': 6098},{'name': 'availabla2z', 'id': 6667}]}