Python/ディクショナリからループでキー値と値を取得する方法
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
#navi(../)
* Pythonのディクショナリからループでキー値と値を取得する...
Pythonのディクショナリからループでキー値と値を取得するサ...
(Pythonのディクショナリは、他の言語ではハッシュは連想配列...
#contents
#htmlinsertpcsp(ll-top.html,ll-sp.html)
* 動作確認環境 [#r6fb6b7b]
- Python
$ python --version
Python 2.7.3
- OS
Debian GNU/Linux 7.4 (wheezy)
* 関連記事 [#qbaaa6d7]
-[[Pythonで繰り返しループのサンプル・for>Python/サンプル/...
-[[Pythonで繰り返しループのサンプル・while>Python/サンプ...
-[[Pythonのディクショナリからループでキー値と値を取得する...
* サンプルコード [#b2eaae87]
以下のサンプルコードは、ディクショナリのキーのみ、キーと...
指定なし、iteritems()、itervalues()により動作が異なってき...
d = {"1st":"sakura", "2nd":"suzuran", "3rd":"tsubaki"}
# print key value
for key in d:
print key
#print key and value
for key, val in d.iteritems():
print key + " : " + val
#print value
for val in d.itervalues():
print val
実際に上記スクリプトを実行した時の出力です。
2nd
3rd
1st
2nd : suzuran
3rd : tsubaki
1st : sakura
suzuran
tsubaki
sakura
以上、Pythonのディクショナリからキー値および値を取得する...
#htmlinsertpcsp(ll-btm.html,ll-sp.html)
終了行:
#navi(../)
* Pythonのディクショナリからループでキー値と値を取得する...
Pythonのディクショナリからループでキー値と値を取得するサ...
(Pythonのディクショナリは、他の言語ではハッシュは連想配列...
#contents
#htmlinsertpcsp(ll-top.html,ll-sp.html)
* 動作確認環境 [#r6fb6b7b]
- Python
$ python --version
Python 2.7.3
- OS
Debian GNU/Linux 7.4 (wheezy)
* 関連記事 [#qbaaa6d7]
-[[Pythonで繰り返しループのサンプル・for>Python/サンプル/...
-[[Pythonで繰り返しループのサンプル・while>Python/サンプ...
-[[Pythonのディクショナリからループでキー値と値を取得する...
* サンプルコード [#b2eaae87]
以下のサンプルコードは、ディクショナリのキーのみ、キーと...
指定なし、iteritems()、itervalues()により動作が異なってき...
d = {"1st":"sakura", "2nd":"suzuran", "3rd":"tsubaki"}
# print key value
for key in d:
print key
#print key and value
for key, val in d.iteritems():
print key + " : " + val
#print value
for val in d.itervalues():
print val
実際に上記スクリプトを実行した時の出力です。
2nd
3rd
1st
2nd : suzuran
3rd : tsubaki
1st : sakura
suzuran
tsubaki
sakura
以上、Pythonのディクショナリからキー値および値を取得する...
#htmlinsertpcsp(ll-btm.html,ll-sp.html)
ページ名: