比较包含字典列表值的字典

时间:2020-05-08 14:11:54

标签: python-3.x dictionary

我有两个字典:

    dict1 = {'Warning': [{'User account': 'User doesnot exist'},
                         {'Login': 'Login failed'}],
             'Error': [{'Monitoring': 'Monitoring failed due to system crash'},
                       {'Scheduler': 'Scheduler stopped running'}]}

dict2 = {'Warning': [{'User account': 'User doesnot exist'},
                     {'Login': 'Multiple logins attempted'},
                     {'Version': 'Version doesnot match'}],
         'Error': [{'Monitoring': 'Monitoring failed due to system crash'},
                   {'Scheduler': 'Scheduler never inititated'}],
         'Critical': [{'Memory': 'Memory overflow'}]}

我必须比较两个字典,如果dict2的值(字典列表)在dict1中不常见,则必须返回它们: 预期的输出是:

result = {'Warning': [{'Login': 'Multiple logins attempted'},
                      {'Version': 'Version doesnot match'}],
          'Error': [{'Scheduler': 'Scheduler never inititated'}],
          'Critical': [{'Memory': 'Memory overflow'}]}

我们非常感谢您的帮助。

0 个答案:

没有答案