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')


出处:https://blog.csdn.net/lachesis999/article/details/53354153

猜你喜欢

转载自blog.csdn.net/jackliu16/article/details/80226947