合并字典列表时如何删除对偶

时间:2018-10-28 18:43:12

标签: python

我正在尝试对以下词典列表进行合并,但是我得到了重复项,如何删除重复项?

x =[{'Charles':'father','John':'son'},{'Charles':'father'}]
f =[{'Sarah':'mother','Peter':'secondson'},{'Charles':'father'}]
res = list(x+f)
print res

输出:-

[{'Charles': 'father', 'John': 'son'}, {'Charles': 'father'}, {'Sarah': 'mother', 'Peter': 'secondson'}, {'Charles': 'father'}]

预期的输出:-

[{'Charles': 'father', 'John': 'son'}, {'Charles': 'father'}, {'Sarah': 'mother', 'Peter': 'secondson'}]

0 个答案:

没有答案