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
相关文章
封装 Python 时间处理库创建自己的TimeUtil类示例
这篇文章主要为大家介绍了封装 Python 时间处理库创建自己的TimeUtil类示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步早日升职加薪2023-05-05
如何解决pycharm中用matplotlib画图不显示中文的问题
这篇文章主要介绍了如何解决pycharm中用matplotlib画图不显示中文的问题,文章围绕主题展开详细的内容介绍,具有一定的参考价值,感兴趣的小伙伴可以参考一下2022-06-06


最新评论