Calculate difference in keys contained in two Python dictionaries

后端 未结 21 1447
眼角桃花
眼角桃花 2020-11-27 09:33

Suppose I have two Python dictionaries - dictA and dictB. I need to find out if there are any keys which are present in dictB but not

21条回答
  •  青春惊慌失措
    2020-11-27 10:04

    If you want a built-in solution for a full comparison with arbitrary dict structures, @Maxx's answer is a good start.

    import unittest
    
    test = unittest.TestCase()
    test.assertEqual(dictA, dictB)
    

提交回复
热议问题