Python Dictionary items() Method
Description
The Python Dictionary items() method returns a list of traversable (key, value) tuple pairs.
Syntax
The syntax of the items() method is:
dict.items()
Parameters
- NA。
Return Value
Returns a list of traversable (key, value) tuple pairs.
Example
The following example demonstrates how to use the items() method:
Example (Python 2.0+)
#!/usr/bin/python
# coding=utf-8
tinydict = {'Google': 'www.google.com', 'Example': 'www.example.com', 'taobao': 'www.taobao.com'}
print "Dictionary values: %s" % tinydict.items()
# Traverse the dictionary list
for key,values in tinydict.items():
print key,values
The output of the above example is:
字典值 : [('Google', 'www.google.com'), ('taobao', 'www.taobao.com'), ('Example', 'www.example.com')]
Google www.google.com
taobao www.taobao.com
Example www.example.com
Other Extensions
Python Dictionary