開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python (プログラミング言語)
初めてのPerl 第6版 (Randal L. Schwartz (著)、brian d foy (著)、Tom Phoenix (著)、近藤 嘉雪 (翻訳)、オライリージャパン)の14章(文字列処理とソート)の14.5(練習問題)1.をPythonで考えてみる。
14.5(練習問題)1.
コード(BBEdit, Emacs)
sample304_1.py
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
import sys
numbers = sys.stdin.read().split()
cols = max(map(len, numbers))
s = '{0:>' + str(cols) + 's}'
for number in sorted(numbers, key=lambda x: float(x)) :
print(s.format(number))
入出力結果(Terminal)
$ ./sample304_1.py < numbers.txt
-10
1.50
1.5
3.14159
04
4
17
666
1000
2001
90210
$ cat numbers.txt
17 1000 04 1.50 3.14159 -10 1.5 4 2001 90210 666
$
0 コメント:
コメントを投稿