Automate the Boring Stuff with Python:
Practical Programming for Total Beginners
(No Starch Press)
Al Sweigart (著)
開発環境
- OS X El Capitan - Apple (OS)
- Emacs (Text Editor)
- Python 3.5 (プログラミング言語)
Automate the Boring Stuff with Python: Practical Programming for Total Beginners (Al Sweigart (著)、No Starch Press)のPart Ⅰ.(Python Programming Basics)、Chapter 6.(Manipulating Strings)、Practice Projects: Practice Projects(Table Printer)を解いてみる。
Practice Projects: Practice Projects(Table Printer)
コード(Emacs)
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
def printTable(table_data):
col_widths = map(lambda x: max(x),
map(lambda y:
map(lambda z: len(z), y),
table_data))
col_widths = list(col_widths)
for i in range(len(table_data[0])):
for j in range(len(table_data)):
print(table_data[j][i].rjust(col_widths[j] + 1), end='')
print()
tableData = [['apples', 'oranges', 'cherries', 'banana'],
['Alice', 'Bob', 'Carol', 'David'],
['dogs', 'cats', 'moose', 'goose']]
printTable(tableData)
入出力結果(Terminal, IPython)
$ ./sample1.py apples Alice dogs oranges Bob cats cherries Carol moose banana David goose $
0 コメント:
コメントを投稿