在python循环中比较2个字典

时间:2019-06-10 03:30:10

标签: python

我有4个字典,它们的值在流程运行期间添加,因此键值可以不同,但​​键保持不变以进行比较,例如在这里,我想将dic1与dict2比较,将dict3与dict4比较,并得到差值。

在循环中,我尝试使用set,但在循环中不起作用:

for key in dic2.keys():
   value = set(dic2)-set(dic1)
   if value:
      print "different ".value
   else:
      print "identical"

dict1= 
[{EMOTR-1 NTK536AA : ls -1 /var/crash |tail -n +2
bbb-metro-2588-1559818317.txt
bbb-metro-3512-1559818163.core.gz
bbb-metro-3512-1559818163.txt
bash-4.1#
,XC-7 NTK615AA : ls -1 /var/crash |tail -n +2
bash-4.1#}]

dict2=
[{EMOTR-1 NTK536AA : ls -1 /var/crash |tail -n +2
bbb-metro-2588-1559818317.txt
bbb-metro-3512-1559818163.core.gz
bbb-metro-3512-1559818163.txt
cesd-pslm.20190606.102805+0000.3751
bash-4.1#,XC-7 NTK615AA : ls -1 /var/crash |tail -n +2
bash-4.1#}]

dic3=
[{EMOTR-1 NTK536AA : ls -1 /var/crash/old |tail -n +2
cesd-pslm-3759-1559815563.txt
cesd-pslm-7197-1559815583.core.gz
cesd-pslm-7197-1559815583.txt
bash-4.1#
}]

dic4=
[{EMOTR-1 NTK536AA : ls -1 /var/crash/old |tail -n +2
cesd-pslm-3759-1559815563.txt
cesd-pslm-7197-1559815583.core.gz
cesd-pslm-7197-1559815583.txt
test.txt
bash-4.1#
}]

0 个答案:

没有答案