如何獲得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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章