開発環境
- macOS High Sierra - Apple
- Emacs (Text Editor)
- Python 3.7 (プログラミング言語)
入門 Python 3 (Bill Lubanovic (著)、斎藤 康毅 (監修)、長尾 高弘 (翻訳)、オライリージャパン)の5章(Pyの化粧箱: モジュール、パッケージ、プログラム)、5.7(復習問題)5-5、6、7.を取り組んでみる。
コード(Emacs)
Python 3
#!/usr/bin/env python3
from collections import OrderedDict, defaultdict
print('5.')
plain = {'a': 1, 'b': 2, 'c': 3}
print(plain)
print('6.')
fancy = OrderedDict(plain)
print(fancy)
print('7.')
dict_of_lists = defaultdict(list)
dict_of_lists['a'].append('something for a')
print(dict_of_lists)
入出力結果(Terminal, Jupyter(IPython))
$ ./sample2.py
5.
{'a': 1, 'b': 2, 'c': 3}
6.
OrderedDict([('a', 1), ('b', 2), ('c', 3)])
7.
defaultdict(<class 'list'>, {'a': ['something for a']})
$
0 コメント:
コメントを投稿