Python中的字典遍历备忘
备忘一下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
相关文章
Windows安装Anaconda并且配置国内镜像的详细教程
我们在学习 Python 的时候需要不同的 Python 版本,关系到电脑环境变量配置换来换去很是麻烦,所以这个时候我们需要一个虚拟的 Python 环境变量,这篇文章主要介绍了Windows安装Anaconda并且配置国内镜像教程,需要的朋友可以参考下2023-01-01
最新评论