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