開発環境
- OS X Lion - Apple(OS)
- TextWrangler(Text Editor) (BBEditの無料機能制限版、light版)
- Script言語: Python
『初めてのPython 第3版』(Mark Lutz 著、夏目 大 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-393-7) のIV部(関数)まとめ演習5(ディクショナリのコピー)を解いてみる。
5.
コード(TextWrangler)
#!/usr/bin/env python #encoding: utf-8 def copyDict(d): result = {} for key in d.keys(): result[key] = d[key] return result
入出力結果(Terminal)
$ python Python 2.7.2 (default, Feb 12 2012, 23:50:38) [GCC 4.2.1 Compatible Apple Clang 3.0 (tags/Apple/clang-211.12)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from sample import copyDict >>> d={'a':1,'b':2} >>> d1=copyDict(d) >>> d {'a': 1, 'b': 2} >>> d1 {'a': 1, 'b': 2} >>> quit() $
0 コメント:
コメントを投稿