Python学习笔记(四) 关于dictionary遍历
来源:互联网 发布:上海数据恢复哪家好 编辑:程序博客网 时间:2024/05/15 03:43
在python中,提供了一种可以快速查找的dictionary数据类型,与tuple和list大同小异,但是用起来却很方便:
d={0:'zero',3:'a tuple', 'two':[1,2,3],'one':1}>>> for c in d.iterkeys():... print c;...03twoone>>> for c in d.iterkeys():... print d[c]...zeroa tuple[1, 2, 3]1>>> for c in d.iterkeys():... print c,d[c];...0 zero3 a tupletwo [1, 2, 3]one 1
>>> for c in d.itervalues():... print c...zeroa tuple[1, 2, 3]1
>>> for c in d.iteritems():... print c;...(0, 'zero')(3, 'a tuple')('two', [1, 2, 3])('one', 1)>>> for k,v in d.iteritems():... print 'd[',k,']=',v...d[ 0 ]= zerod[ 3 ]= a tupled[ two ]= [1, 2, 3]d[ one ]= 1
三种遍历方式分别为iterkeys(),itervalues(),iteritems()
d.iterkeys()返回值为dictionary的键值,同时也可以以类似C语言中数组的形式返回函数的值
d.itervalues()返回值仅为dictionary的值
d.iteritems()允许遍历dictionary的全部值,一次遍历即为全体值。
0 0
- Python学习笔记(四) 关于dictionary遍历
- python学习笔记--Dictionary
- Python学习笔记(八)-- Python字典(Dictionary)
- Python学习笔记(十八)----Python 字典(Dictionary)
- Python学习笔记(四)—列表(list)、元组(tuple)和字典(dictionary)、集合(set)
- python学习笔记16:tuple, set, dictionary
- 学习笔记(四)图的遍历
- Python学习笔记(四)
- python学习笔记(四)
- Python学习笔记(四)
- python学习笔记(四)
- Python学习笔记(四)
- python 学习笔记(四)
- python学习笔记(四)
- Python学习笔记(四)
- Python学习笔记(四)
- Python学习笔记(四)
- python学习笔记(四)
- vs2010中引入boost
- CPC客户端编写新申请时报错异常来自 HRESULT:0x80040154 (REGDB_E_CLASSNOTREG))
- linux在文件尾部插入一行
- 关键字搜索十次存入memcache
- ReLu(Rectified Linear Units)激活函数
- Python学习笔记(四) 关于dictionary遍历
- HTML的学习笔记
- CDN加速服务,CDN公共库汇总
- 地主算法之判断牌型
- 全局函数调用成员函数
- Java内部类详解(一)
- springmvc 工作原理
- 配置JAVA的环境变量
- 诸事不顺的时候我们该怎么办?