python字典中items()和iteritems()的区别

items()返回的是列表对象,而iteritems()返回的是iterator对象。例如:


print dic.items() #[('a', 'hello'), ('c', 'you'), ('b', 'how')]


print dic.iteritems() #<dictionary-itemiterator object at 0x020E9A50>


深究:iteritor是迭代器的意思,一次反悔一个数据项,知道没有为止


for i in dic.iteritems():

print i

结果:('a', 'hello')

('c', 'you')

('b', 'how')



转自

http://www.aichengxu.com/view/66357