python3两个字典的合并
两个字典的合并其实很简单,直接用dict的update即可,代码如下:
# /usr/bin/python3# -*- encoding: utf-8 -*-import json
param1 = """{"a":"1","b":"2"}"""param2 = """{"b":"3","c":"4"}"""json1 = json.loads(param1)
json2 = json.loads(param2)
print("json1: ", json1)print("json2: ", json2)merge = dict(json1)merge.update(json2)print("merge: ", merge)
得到结果如下:
json1: {'a': '1', 'b': '2'}json2: {'c': '4', 'b': '3'}merge: {'c': '4', 'a': '1', 'b': '3'}