手机
当前位置:查字典教程网 >脚本专栏 >python >Python中的字典遍历备忘
Python中的字典遍历备忘
摘要:备忘一下python中的字典如何遍历,没有什么太多技术含量.仅供作为初学者的我参考.复制代码代码如下:#!/usr/bin/envpytho...

备忘一下python中的字典如何遍历,没有什么太多技术含量.仅供作为初学者的我参考.

复制代码 代码如下:

#!/usr/bin/env python

# coding=utf-8

demoDict = {'1':'Chrome', '2':'Android'}

for key in demoDict.keys():

print key

for value in demoDict.values():

print value

for key in demoDict:

print key, demoDict[key]

for key, value in demoDict.items():

print key, value

for key in demoDict.iterkeys():

print key

for value in demoDict.itervalues():

print value

for key, value in demoDict.iteritems():

print key, value

print 'dict.keys()=', demoDict.keys(), ';dict.iterkeys()=', demoDict.iterkeys()

interitems和iterms区别

参考 http://stackoverflow.com/questions/10458437/python-what-is-the-difference-between-dict-items-and-dict-iteritems

【Python中的字典遍历备忘】相关文章:

python创建和使用字典实例详解

Python Trie树实现字典排序

Python字符转换

Python中删除文件的程序代码

python中的内置函数getattr()介绍及示例

python中cPickle用法例子分享

Python类的基础入门知识

Python中的CURL PycURL使用例子

Python中使用中文的方法

Python中for循环详解

精品推荐
分类导航