自信,努力,坚持
python 字典比较
上一篇 /
下一篇 2011-07-28 14:08:44
/ 个人分类:python
参考了http://blog.csdn.net/linkyou/article/details/6440378这篇
文章的方法,不过最后我偷懒了下,只做了两步:
1、比较长度,如果数组长度不对,那肯定是不对的,直接out
if str(len(input)) != str(len(expect)) :
print "the inputdic len:%s and the expectdic len:%s !" % (str(len(input)), str(len(expect)))
assert str(len(input))== str(len(expect)), "the inputdic's len is diffent from the expectdic's len!"
2、长度正确后,直接比较字典,实验过这样也能比较,只是无法指出具体哪里不一样,方法可根据需求改进下
# 比较字典
if expect != input:
print "the inputdic:%s and the expectdic:%s !" % (input, expect)
收藏
举报
TAG: