dict两种遍历方法
采用for...in...遍历:
>>> for i in dd: ... print("%s:%s"%(i,dd[i])) ... 1:chen 2:hang 3:wust 4:wang 5:yadan 6:wuhan 8:xinzhou 9:haha
采用dd.items()遍历:
>>> for k,v in dd.items(): ... print("%s:%s"%(k,v)) ... 1:chen 2:hang 3:wust 4:wang 5:yadan 6:wuhan 8:xinzhou 9:haha
dd为:
>>> dd {1: 'chen', 2: 'hang', 3: 'wust', 4: 'wang', 5: 'yadan', 6: 'wuhan', 8: 'xinzhou', 9: 'haha'}
dd