python 字典items和iteritems

3.4.6 items和iteritems

  1. 说明:items以列表方式返回字典中的键值对,iteritems以迭代器对象 返回键值对儿(Python3中不再支持);
  2. 例子:
     1:  >>> x
    
     2:  {'name': 'Bill'}
    
     3:  >>> x.items()
    
     4:  dict_items([('name', 'Bill')])
    
     5:  
    
     6:  #python3中不再包含iteritems
    
     7:  >>> x.iteritems()
    
     8:  Traceback (most recent call last):
    
     9:    File "<pyshell#66>", line 1, in <module>
    
    10:      x.iteritems()
    
    11:  AttributeError: 'dict' object has no attribute 'iteritems'
    
    12:  

posted on 2015-08-10 22:28  Mountain's_blog  阅读(7752)  评论(0编辑  收藏  举报

导航