In this article, we'll learn about the Python
items function in the Python dictionary, what I mean by the
tems function , and how this function will be answered in the next article.
Describe
The Python dictionary (Dictionary) items () function returns an array of traversed (key, value) tuples in a list.
Grammar
The items () method syntax:
Dict.items ()
Parameters
NA.
return value
Returns an array of (key, value) tuples that can be traversed.
Instance
The following example shows how to use the items () function:
#!/usr/bin/python# coding=utf-8dict = {' Google ': ' www.google.com ', ' runoob ': ' www.runoob.com ', ' Taobao ': ' Www.taobao.com '}print ' dictionary value:%s "% Dict.items () # Traverse dictionary list for key, values in Dict.items (): print Key, values
The result of the above example output is:
Dictionary values: [(' Google ', ' www.google.com '), (' Taobao ', ' www.taobao.com '), (' Runoob ', ' www.runoob.com ')]google Www.google.comtaobao Www.taobao.comRunoob www.runoob.com