How do I merge dictionaries together in Python?

后端 未结 7 1783
无人及你
无人及你 2020-12-04 17:05
d3 = dict(d1, **d2)

I understand that this merges the dictionary. But, is it unique? What if d1 has the same key as d2 but different value? I woul

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-04 17:45

    Trey Hunner has a nice blog post outlining several options for merging multiple dictionaries, including (for python3.3+) ChainMap and dictionary unpacking.

提交回复
热议问题