This article mainly introduces the dictionary traversal memo in Python. This article lists a variety of dictionary traversal methods, which are suitable for beginners to view and briefly explains the differences between interitems and iterms, for more information, see how to traverse the dictionary in python. it is only for my reference as a beginner.
The code is as follows:
#! /Usr/bin/env python
# Coding = UTF-8
DemoDict = {'1': 'chromi', '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 and iterms
Reference http://stackoverflow.com/questions/10458437/python-what-is-the-difference-between-dict-items-and-dict-iteritems