python 遍历字典

时间:2014-05-04 20:13:19   收藏:0   阅读:401
bubuko.com,布布扣
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 
bubuko.com,布布扣

 

python 遍历字典,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!