Python3字典中items()和python2.x中iteritems()有什么区别
在Python2.x中,items( )用于 返回一个字典的拷贝列表【Returns a copy of the list of all items (key/value pairs) in D】,占额外的内存。
iteritems() 用于返回本身字典列表操作后的迭代【Returns an iterator on all items(key/value pairs) in D】,不占用额外的内存。
Python 3.x 里面,iteritems() 和 viewitems() 这两个方法都已经废除了,而 items() 得到的结果是和 2.x 里面 viewitems() 一致的。在3.x 里 用 items()替换iteritems() ,可以用于 for 来循环遍历。
例:
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0
for key, value in d.items():
sum = sum + value
print(key, ':' ,value)
print('平均分为:' ,sum /len(d))
Python3字典中items()和python2.x中iteritems()有什么区别的更多相关文章
- python3字典中items()和python2.x中iteritems()有什么不同?
在Python2.x中: items() 用于返回一个字典的拷贝列表[Returns a copy of the list of all items (key/value pairs) in D],占 ...
- [Python3 填坑] 012 字典的遍历在 Python2 与 Python3 中区别
目录 1. print( 坑的信息 ) 2. 开始填坑 2.1 Python2 中字典的遍历 2.2 Python3 中字典的遍历 2.3 结论 1. print( 坑的信息 ) 挖坑时间:2019/ ...
- python3 items() 与 python2 中iteritems()的区别
在Python2.x中, iteritems() 用于返回本身字典列表操作后的迭代 Python 3.x 里面, iteritems() 方法已经废除了,而 items() 得到的结果是和 2.x 里 ...
- centos7安装Python3的过程中会和Python2.7版本冲突导致yum版本比对应,致使yum不能使用的问题。
centos7安装Python3的过程中会和Python2.7版本冲突导致yum版本比对应,致使yum不能使用的问题. 原因:yum调用Python,启动程/usr/bin/yum就是一个python ...
- Win中同时安装python2和python3及SulimeText3的python IDE搭建
一.下载安装Sublime Text3,初衷是不想忍受pycharm的打开速度,想享受下飞的质感.Sublime Text3的安装已经久远,请自行google. 二.安装python2.7与pytho ...
- nose在python2与python3中的包的自动发现用例的区别
最近在使用python3,同样装了nose,发现自动发现用例总是有问题,如下面的代码结婚 testcase |------ __init__.py |------ test_bb.py test_bb ...
- Python2/3中的urllib库
urllib库对照速查表 Python2.X Python3.X urllib urllib.request, urllib.error, urllib.parse urllib2 urllib.re ...
- 删除centos7中自带有python2.7
删除centos7中自带有python2. ()强制删除已安装python及其关联 # rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps ...
- Android开发(十五)——ListView中Items的间距margin
ListView中Items没有margin 参考:http://www.cnblogs.com/xitang/p/3677528.html
随机推荐
- Mac下SVN服务器环境的搭建和配置(除展示图片外,所有命令在Linux/Unix下适用)
这几天领导没有安排工作,闲着没事就想把自己这两年做iOS开发时感觉知识有欠缺的地方想好好深入地补习一下,昨天和今天就计划好好学习下SVN和git的从创建和到原理,到命令,到界面的使用.一不小心被另一领 ...
- Block编程值得注意的那些事儿
[深入浅出Cocoa]Block编程值得注意的那些事儿 [深入浅出Cocoa]Block编程值得注意的那些事儿 罗朝辉 (http://www.cnblogs.com/kesalin/) 本文遵循 ...
- C语言:typedef 跟 define 的区别
typedef (int*) pINT1;以及下面这行:#define pINT2 int* pINT1 a,b; 与pINT2 a,b; 定义的a,b 有差别吗 回答: typedef作为类型定义关 ...
- Android如何分析和研究Monkey Log文件
Log 在android中的地位非常重要,要是作为一个android程序员不能过分析log这关,算是android没有入门吧 . 下面我们就来说说如何处理log文件 . 什么时候会有Log文件的产生 ...
- Spring处理器
Spring容器内部工作机制 Spring的AbstractApplicationContext是ApplicationContext抽象实现类,该抽象类的refresh()方法定义了Spring容器 ...
- 看了这篇文章,Java编程速度我都惊呆了
熟记于心,打遍天下,(开始装了) 保存 Ctrl+s (这个就不用解释了吧!!!!) 注释代码 Ctrl+/ 取消注释 Ctrl+/代码辅助 Alt+/ 快速修复 ...
- 4 Values whose Sum is 0_upper_bound&&ower_bound
Description The SUM problem can be formulated as follows: given four lists A, B, C, D of integer val ...
- Chocolate_DP
Description In 2100, ACM chocolate will be one of the favorite foods in the world. "Green, oran ...
- iOS教程
iOS绘图教程: http://www.cocoachina.com/industry/20140115/7703.html iOS基础教程:--包含脚本 swift http://bbs.zxope ...
- 13、SQL基础整理(流程控制begin……end)
流程控制 begin ……end将一个语句块包含起来,中间可以写任何语句 格式: begin--开始 select *from student end--结束 if declare @bianlian ...