遍历python字典几种方法
2012-03-14 22:52
691 查看
脚本:
执行结果:
本文出自 “Larry学习之路” 博客,请务必保留此出处http://5iqiong.blog.51cto.com/2999926/806230
#!/usr/bin/python dict={"a":"apple","b":"banana","o":"orange"} print "##########dict######################" for i in dict: print "dict[%s]=" % i,dict[i] print "###########items#####################" for (k,v) in dict.items(): print "dict[%s]=" % k,v print "###########iteritems#################" for k,v in dict.iteritems(): print "dict[%s]=" % k,v print "###########iterkeys,itervalues#######" for k,v in zip(dict.iterkeys(),dict.itervalues()): print "dict[%s]=" % k,v
执行结果:
##########dict###################### dict[a]= apple dict[b]= banana dict[o]= orange ###########items##################### dict[a]= apple dict[b]= banana dict[o]= orange ###########iteritems################# dict[a]= apple dict[b]= banana dict[o]= orange ###########iterkeys,itervalues####### dict[a]= apple dict[b]= banana dict[o]= orange
本文出自 “Larry学习之路” 博客,请务必保留此出处http://5iqiong.blog.51cto.com/2999926/806230
相关文章推荐
- 遍历python字典的几种方法
- 遍历python字典几种方法 分类: python 2013-01-22 13:40 332人阅读 评论(0) 收藏
- 遍历python字典几种方法
- Python遍历字典dict的几种方法
- 遍历python字典几种方法
- 遍历python字典几种方法
- 遍历python字典的几种方法
- 遍历python字典几种方法
- 遍历python字典几种方法
- 遍历python字典几种方法
- 遍历python字典几种方法
- 遍历python字典几种方法
- 遍历python字典几种方法
- 遍历python字典几种方法
- 遍历python字典几种方法
- 遍历python字典几种方法
- 遍历python字典几种方法
- 遍历python字典几种方法总结(推荐)
- [python]遍历字典dict的几种方法
- 遍历python字典的几种方法