開発環境
- macOS High Sierra - Apple
- Emacs (Text Editor)
- Python 3.6 (プログラミング言語)
入門 Python 3 (Bill Lubanovic (著)、斎藤 康毅 (監修)、長尾 高弘 (翻訳)、オライリージャパン)の3章(Pyの具: リスト、タプル、辞書、集合)、3.8(復習問題)15、16、17、18.を取り組んでみる。
コード(Emacs)
Python 3
#!/usr/bin/env python3
print('3-15')
life = {
'animals': {
'cats': [
'Henri',
'Grumpy',
'Lucy'
],
'octopi': {},
'emus': {}
},
'plants': {},
'other': {}
}
print(life)
print('3-16')
print(life.keys())
print('3-17')
print(life['animals'].keys())
print('3-18')
print(life['animals']['cats'])
入出力結果(Terminal, Jupyter(IPython))
$ ./sample5.py
3-15
{'animals': {'cats': ['Henri', 'Grumpy', 'Lucy'], 'octopi': {}, 'emus': {}}, 'plants': {}, 'other': {}}
3-16
dict_keys(['animals', 'plants', 'other'])
3-17
dict_keys(['cats', 'octopi', 'emus'])
3-18
['Henri', 'Grumpy', 'Lucy']
$
0 コメント:
コメントを投稿