開発環境
- OS X El Capitan - Apple (OS)
- Emacs (Text Editor)
- Python 3.5 (プログラミング言語)
Introducing Python: Modern Computing in Simple Packages (Bill Lubanovic (著)、 O'Reilly Media)のChapter 5(Py Boxes: Modules, Packages, and Programs)、Things to Do 5.1-7.を取り組んでみる。
Things to Do 5.1-7.
コード(Emacs)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def hours():
print('Open 9-5 daily')
plain = dict(a=1, b=2, c=3)
print(plain)
import collections
fancy = collections.OrderedDict([
('a', 1),
('b', 2),
('c', 3)
])
print(fancy)
dict_of_lists = collections.defaultdict(list)
dict_of_lists['a'].append('something for a')
print(dict_of_lists['a'])
入出力結果(Terminal, IPython)
$ ipython
Python 3.5.2 (default, Jun 27 2016, 03:10:38)
Type "copyright", "credits" or "license" for more information.
IPython 4.1.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import zoo
In [2]: zoo.hours()
Open 9-5 daily
In [3]: import zoo as menagerie
In [4]: menagerie.hours()
Open 9-5 daily
In [5]: from zoo import hours
In [6]: hours()
Open 9-5 daily
In [7]: from zoo import hours as info
In [8]: info()
Open 9-5 daily
In [9]: paste
plain = dict(a=1, b=2, c=3)
print(plain)
## -- End pasted text --
{'a': 1, 'c': 3, 'b': 2}
In [10]: %paste
import collections
fancy = collections.OrderedDict([
('a', 1),
('b', 2),
('c', 3)
])
print(fancy)
## -- End pasted text --
OrderedDict([('a', 1), ('b', 2), ('c', 3)])
In [11]: %paste
dict_of_lists = collections.defaultdict(list)
dict_of_lists['a'].append('something for a')
print(dict_of_lists['a'])
## -- End pasted text --
['something for a']
In [12]: dict_of_lists
Out[12]: defaultdict(list, {'a': ['something for a']})
In [13]: quit()
$
0 コメント:
コメントを投稿