Python2中的dict.items()和dict.iteritems()有什么区别?
dict.items()和之间有适用的区别dict.iteritems()吗? 从Python文档: dict.items():返回字典的(键,值)对列表的副本。 dict.iteritems():在字典的(键,值)对上返回迭代器。 如果我运行下面的代码,每个似乎都返回对同一对象的引用。我缺少任何细微的差异吗? #!/usr/bin/python d={1:'one',2:'two',3:'three'} print 'd.items():' for k,v in d.items(): if d[k] is v: print '\tthey are the same object' else: print '\tthey are different' print 'd.iteritems():' for k,v in d.iteritems(): if d[k] is v: print '\tthey are the same object' else: print '\tthey are different' 输出: …