2018年8月12日日曜日

開発環境

入門 Python 3 (Bill Lubanovic (著)、斎藤 康毅 (監修)、長尾 高弘 (翻訳)、オライリージャパン)の3章(Pyの具: リスト、タプル、辞書、集合)、3.8(復習問題)3-15、16、17、18.を取り組んでみる。

コード(Emacs)

Python 3

#!/usr/bin/env python3
import pprint

print('15.')

life = {
    'animals': {
        'cats': ['Henri', 'Grumpy', 'Lucy'],
        'octopi': {},
        'emus': {},
    },
    'plants': {},
    'other': {},
}

print(life)
pprint.pprint(life)

print('16.')
print(list(life.keys()))

print('17.')
print(list(life['animals'].keys()))

print('18.')
print(life['animals']['cats'])

入出力結果(Terminal, Jupyter(IPython))

$ ./sample5.py
15.
{'animals': {'cats': ['Henri', 'Grumpy', 'Lucy'], 'octopi': {}, 'emus': {}}, 'plants': {}, 'other': {}}
{'animals': {'cats': ['Henri', 'Grumpy', 'Lucy'], 'emus': {}, 'octopi': {}},
 'other': {},
 'plants': {}}
16.
['animals', 'plants', 'other']
17.
['cats', 'octopi', 'emus']
18.
['Henri', 'Grumpy', 'Lucy']
$

0 コメント:

コメントを投稿