Python中的字典遍历备忘
程序员文章站
2023-11-23 17:48:28
备忘一下python中的字典如何遍历,没有什么太多技术含量.仅供作为初学者的我参考.
复制代码 代码如下:
#!/usr/bin/env python
# codin...
备忘一下python中的字典如何遍历,没有什么太多技术含量.仅供作为初学者的我参考.
复制代码 代码如下:
#!/usr/bin/env python
# coding=utf-8
demodict = {'1':'chrome', '2':'android'}
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://*.com/questions/10458437/python-what-is-the-difference-between-dict-items-and-dict-iteritems