【发布时间】:2014-09-15 16:38:22
【问题描述】:
如果我有两个如下所示的字典:
a = {"fruit":["orange", "lemon"], "vegetable":["carrot", "tomato"]}
b = {"fruit":["banana", "lime"]}
有没有一种方法可以更新字典“a”,这样我就不会覆盖以前的数据,而是简单地附加它,这样我的结果就会像这样?
a = {"fruit":["orange", "lemon", "banana", "lime"], "vegetable": ["carrot", "tomato"]}
我知道有类似的东西,但不幸的是它重写了值,这不是我想要做的:
a.update(b)
#returns a dictionary like the following {"fruit":["banana", "lime"], "vegetable":["carrot","tomato"]}, again, not what I want.
【问题讨论】:
标签: python python-3.x dictionary python-3.4