虺文忠,江泽慧的丈夫,2013北京公务员
备忘一下python中的字典如何遍历,没有什么太多技术含量.仅供作为初学者的我参考.
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()
interitems和iterms区别
参考 http://stackoverflow.com/questions/10458437/python-what-is-the-difference-between-dict-items-and-dict-iteritems
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Python 实现将numpy中的nan和inf,nan替换成对应的均值
python爬虫把url链接编码成gbk2312格式过程解析
网友评论