開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python 3.4 (プログラミング言語)
Learning Python (Mark Lutz (著)、Oreilly & Associates Inc)のPART Ⅲ.(Statements and Syntax)、Test Your Knowledge: Part Ⅲ Exercises、3.(Sorting dictionaries)を解いてみる。
その他参考書籍
- Pythonチュートリアル 第2版
- Python クックブック 第2版 (原書(最新版))
- Programming Python
- Python Pocket Reference (Pocket Reference (O'Reilly))
3.(Sorting dictionaries)
コード(BBEdit)
sample3.py
#!/usr/bin/env python3 #-*- coding: utf-8 -*- d = {5:'a', 1:'b', 4:'c', 2:'d', 3:'e'} ks = list(d.keys()) ks.sort() for k in ks: print(d[k]) print() for k in sorted(d): print(d[k])
入出力結果(Terminal, IPython)
$ ./sample3.py b d e c a b d e c a $
0 コメント:
コメントを投稿