Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Dictionary items() method

Python Dictionary items() method

Python Dictionary Python Dictionary


Description

The Python Dictionary items() function returns a list of iterable (key, value) tuple pairs.

Syntax

items() method syntax:


dict.items()

Parameters

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

= {

'

Google

'

:

'

www.google.com

'

,

'

Runoob

'

:

'

www.runoob.com

'

,

'

taobao

'

:

'

www.taobao.com

'

}

print

"

Dictionary values: %s

"

%

tinydict

.

items

(

)

Iterate over 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'), ('Runoob', 'www.runoob.com')]
Google www.google.com
taobao www.taobao.com
Runoob www.runoob.com

Python Dictionary Python Dictionary