我希望将一个字典中填充的汇总数字与另一个字典中的键和值进行比较,以确定两者之间的差异。 我只能得出以下结论:
for i in res.keys():
if res2.get(i):
print 'match',i
else:
print i,'does not match'
for i in res2.keys():
if res.get(i):
print 'match',i
else:
print i,'does not match'
for i in res.values():
if res2.get(i):
print 'match',i
else:
print i,'does not match'
for i in res2.values():
if res.get(i):
print 'match',i
else:
print i,'does not match'
笨重且有错误...需要帮助!
res1 == res2
来比较字典,但你是否还需要找出哪些部分不同呢? - Greg Hewgilldict.keys
是一个无用的函数,a.keys() == list(a)
,而且显式地列出键名也很少有用。 - Jochen Ritzel