源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Python中的字典遍历备忘

  • 时间:2020-05-15 23:01 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Python中的字典遍历备忘
备忘一下python中的字典如何遍历,没有什么太多技术含量.仅供作为初学者的我参考.
[u]复制代码[/u] 代码如下:
#!/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()
[b]interitems和iterms区别[/b] 参考 http://stackoverflow.com/questions/10458437/python-what-is-the-difference-between-dict-items-and-dict-iteritems
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部