I have two dictionaries:
dict1 = { 'url1': '1', 'url2': '2', 'url3': '3', 'url4': '4' }
dict2 = { 'url1': '1', 'url2': '2', 'url5': '5', 'url6': '6' }
and wanted to merge them to come up with a dict that looks like this:
dict_merged = { 'url1': ['1','1'], 'url2': ['2','2'], 'url3': ['3','0'], 'url4': ['4','0'], 'url5': ['0','5'], 'url6': ['0','6'] }
I already have the following code to merge both but how do I assign the default value '0'
if the key is not found in one of the dicts?
dict_merged = dict()
for key in (dict1.keys() | dict2.keys()):
if key in dict1:
merged.setdefault(key, []).append(dict1[key])
if key in dict2:
merged.setdefault(key, []).append(dict2[key])
Thanks in advance!