當前位置:成語大全網 - 新華字典 - python字典中items和iteritems的區別

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