我想要在一个字典中填充聚合数字,并将键和值与另一个字典中的键和值进行比较,以确定两者之间的差异。我只能得出如下结论:比较2个字典中的键和值
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'
笨重和越野车......需要帮助!
两个词典都有相同的一组键吗? – 2012-02-12 23:00:05
你可以用'res1 == res2'来比较dictonaries,你还需要找出哪些*部分不同? – 2012-02-12 23:06:15
'dict.keys'是一个无用的函数,'a.keys()== list(a)'和一个显式的键列表几乎不会有用。 – 2012-02-12 23:50:53