Dictionary traversal memo in Python and python dictionary memo
I have forgotten how to traverse the dictionary in python. There is not much technical content. It is only for my reference as a beginner.
Copy codeThe 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