📜  如何在python代码示例中合并两个具有相同键的字典

📅  最后修改于: 2022-03-11 14:45:07.560000             🧑  作者: Mango

代码示例6
from collections import defaultdict

d1 = {1: 2, 3: 4}
d2 = {1: 6, 3: 7}

dd = defaultdict(list)

for d in (d1, d2): # you can list as many input dicts as you want here
    for key, value in d.items():
        dd[key].append(value)

print(dd)