2014年12月12日金曜日

開発環境

Introducing Python: Modern Computing in Simple Packages(Bill Lubanovic (著)、 O'Reilly Media)のChapter 3(Py Filling: Lists, Tuples, Dictionaries, and Sets)、Things to Do 3.10, 11, 12, 13, 14.を解いてみる。

Things to Do 3.10, 11, 12, 13, 14.

入出力結果(Terminal, IPython)

$ ipython
Python 3.4.2 (default, Nov  1 2014, 16:32:22) 
Type "copyright", "credits" or "license" for more information.

IPython 2.3.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]: e2f = dict(dog='chien', cat='chat', walrus='morse')

In [2]: e2f
Out[2]: {'cat': 'chat', 'walrus': 'morse', 'dog': 'chien'}

In [3]: e2f['walrus']
Out[3]: 'morse'

In [4]: f2e = {}

In [5]: for e, f in e2f.items():
   ...:     f2e[f] = e
   ...: 

In [6]: f2e
Out[6]: {'chien': 'dog', 'morse': 'walrus', 'chat': 'cat'}

In [7]: f2e['chien']
Out[7]: 'dog'

In [8]: set(e2f.keys())
Out[8]: {'cat', 'dog', 'walrus'}

In [9]: quit()
$

0 コメント:

コメントを投稿