Let\'s suppose that I have two dictionaries:
dic1 = { \"first\":1, \"second\":4, \"third\":8}
dic2 = { \"first\":9, \"second\":5, \"fourth\":3}
Create a new dictionary dic
having for keys the keys of dic1
and dic2
and value an empty list, then iterate over dic1
and dic2
appending values to dic
:
dic1 = { "first":1, "second":4, "third":8}
dic2 = { "first":9, "second":5, "fourth":3}
dic = {key:[] for key in list(dic1.keys()) + list(dic2.keys())}
for key in dic1.keys():
dic[key].append(dic1[key])
for key in dic2.keys():
dic[key].append(dic2[key])