记录循环遍历字典操作

一直以来对python的字典的用法不是很熟悉,下午百度了一把,循环字典的方法:呵呵,让我发现了一片好资料:http://5iqiong.blog.51cto.com/2999926/806230 ? ? ? 这个文章写的不错,记录下,以后做备忘,可以来翻翻:

[root@kvm python]# cat dictoper.py#!/usr/bin/env pythondictos={1:'window',2:'unix',3:'centos',4:'redhat'}print "First ways to list dict...."for k in dictos:print k,dictos[k]print "Second way to list dict...."for (k,v) in dictos.items():print k,vprint "Third way to list dict...."for k,v in dictos.iteritems():print k,vprint "Forth way to list dict...."for k,v in zip(dictos.iterkeys(),dictos.itervalues()):print k,v

下面看看效果:

[root@kvm python]# python dictoper.pyFirst ways to list dict....1 window2 unix3 centos4 redhatSecond way to list dict....1 window2 unix3 centos4 redhatThird way to list dict....1 window2 unix3 centos4 redhatForth way to list dict....1 window2 unix3 centos4 redhat
记录循环遍历字典操作

相关文章:

你感兴趣的文章:

标签云: