Calculate difference in keys contained in two Python dictionaries

后端 未结 21 1389
眼角桃花
眼角桃花 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

    what about standart (compare FULL Object)

    PyDev->new PyDev Module->Module: unittest

    import unittest
    
    
    class Test(unittest.TestCase):
    
    
        def testName(self):
            obj1 = {1:1, 2:2}
            obj2 = {1:1, 2:2}
            self.maxDiff = None # sometimes is usefull
            self.assertDictEqual(d1, d2)
    
    if __name__ == "__main__":
        #import sys;sys.argv = ['', 'Test.testName']
    
        unittest.main()
    

提交回复
热议问题