码迷,mamicode.com
首页 > 编程语言 > 详细

python 字典items和iteritems

时间:2015-08-10 23:45:56      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:

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:  

python 字典items和iteritems

标签:

原文地址:http://www.cnblogs.com/100thMountain/p/4719502.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!