python中items()和iteritems()函数的用法

items函数,将一个字典以列表的形式返回,因为字典是无序的,所以返回的列表也是无序的。

a = {'a':1,'b':3}
a.items()
返回a = [('a',1),('b',3)]

iteritems()返回一个迭代器

b = a.iteritems()
list(b) =[('a',1),('b',3)]



for k,v in b:     
    print k,v

返回a 1
      b 3
原文地址:https://www.cnblogs.com/life-need-high-power-laser-gun/p/7518803.html