Python 辞書(Dictionary) items()メソッド

Python 字典Python 辞書


説明

Python 辞書(Dictionary) の items() 関数は、リストとして反復処理可能な (キー, 値) タプルの配列を返します。

構文

items()メソッドの構文:

dict.items()

パラメータ

  • NA。

戻り値

反復処理可能な (キー, 値) タプルの配列を返します。

例

以下の例は、items()関数の使用方法を示しています。

例 (Python 2.0+)

#!/usr/bin/python # coding=utf-8 tinydict = {'Google': 'www.google.com', 'サンプル': 'www.example.com', 'taobao': 'www.taobao.com'} print "辞書値 : %s" % tinydict.items() # 辞書リストを反復処理 for key,values in tinydict.items(): print key,values

上記の例の出力結果:

字典值 : [('Google', 'www.google.com'), ('taobao', 'www.taobao.com'), ('サンプル', 'www.example.com')]
Google www.google.com
taobao www.taobao.com
サンプル www.example.com

Python 字典Python 辞書

その他の拡張