鉴于字典的两个列表的两个列表:的Python:合并字典
>>> lst1 = [{id: 1, x: "one"},{id: 2, x: "two"}]
>>> lst2 = [{id: 2, x: "two"}, {id: 3, x: "three"}]
>>> merge_lists_of_dicts(lst1, lst2) #merge two lists of dictionary items by the "id" key
[{id: 1, x: "one"}, {id: 2, x: "two"}, {id: 3, x: "three"}]
实施merge_lists_of_dicts
基于字典项的键是什么字典合并两列什么办法?
如果lst2 [0] = {id:2,x:“five”}或者如果lst2 [0] = {id:2,y:“y”} – alko
如果“id”相同,但值不是?,如果你的字典只有一个项目,为什么不使用元组?我认为你正在使用字典错误? –
你使用python 3吗? – LostAvatar