0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

『退屈なことはPythonにやらせよう』 6章 6.7 演習プロジェクト回答例

Last updated at Posted at 2020-01-25

6章 6.7 演習プロジェクト回答例

書いてみました。

def print_table(table_data):
    col_widths = [0] * len(table_data)
    for i in range(len(table_data)):
        col_widths[i] = len(max(table_data[i], key=len))

    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()
    
table_data = [['apples', 'oranges', 'cherries', 'banana'],
              ['Alice', 'Bob', 'Carol', 'David'],
              ['dogs', 'cats', 'moose', 'goose']]

print_table(table_data)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?