比较两个字典并基于比较的字典更新字典的解决方案
比较dict1和dict2并根据dict键值更新dict1,其中“ id”是唯一键
dict1={id:1,mobile:'nokia',count:54,size:9}
dict2={id:1,mobile:'nokia',count:63,size:9}
预期输出:
dict1={id:1,mobile:'nokia',count:63,size:9}
答案 0 :(得分:0)
示例代码:
dict1={"id":1,"mobile":'nokia',"count":54,"size":9}
dict2={"id":1,"mobile":'nokia',"count":63,"size":9}
dict1.update(dict2)
print(dict1)
输出:
{'id': 1, 'mobile': 'nokia', 'count': 63, 'size': 9}