如何获得Python中两个字典之间的差异? - How to get the difference between two dictionaries in Python?

问题:

I have two dictionaries, and I need to find the difference between the two, which should give me both a key and a value.我有两本字典,我需要找出两者之间的区别,这应该给我一个键和一个值。

I have searched and found some addons/packages like datadiff and dictdiff-master, but when I try to import them in Python 2.7, it says that no such modules are defined.我搜索并找到了一些插件/包,如 datadiff 和 dictdiff-master,但是当我尝试在 Python 2.7 中导入它们时,它说没有定义这样的模块。

I used a set here:我在这里使用了一套:

first_dict = {}
second_dict = {}
 
value = set(second_dict) - set(first_dict)
print value

My output is:我的输出是:

>>> set(['SCD-3547', 'SCD-3456'])

I am getting only keys, and I need to also get the values.我只得到键,我还需要得到值。


解决方案:

参考: https://stackoom.com/en/question/2DgqW
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章