Dic = {"War and Peace":60,"Les Miserables":88,"A Tale of Two Cities":75,\
"Jane Eyre":23,"Wuthering Heights":56}
これは私がやったことであり、配置はとても面倒です
print("Title","Pages",sep="\t\t\t")
for l,v in Dic.items():
print(l,v,sep="\t\t\t")
Dic = {"War and Peace":60,"Les Miserables":88,"A Tale of Two Cities":75,\
"Jane Eyre":23,"Wuthering Heights":56}
これは私がやったことであり、配置はとても面倒です
print("Title","Pages",sep="\t\t\t")
for l,v in Dic.items():
print(l,v,sep="\t\t\t")
フィールド幅で string.format() を使用するのは良いことです。これにより、広いフィールドに埋め込まれた文字列、つまり空白が埋め込まれた文字列が得られます。
ときどき、1 つのテーブルを使用して Python コードの列を分離し、その結果を *ix "expand" コマンドにパイプします。Expand を使用すると、タブを任意の数のスペースに変換できます。この方法では、プレゼンテーションは Python プログラムにコーディングされません。
例えば:
$ python3 -c 'print(1, "\t", 2)' | expand -30
1 2
>>> d = {"War and Peace":60,"Les Miserables":88,"A Tale of Two Cities":75,\
... "Jane Eyre":23,"Wuthering Heights":56}
>>> print ["%20s%4s"%(k, d[k]) for k in d]
[' Jane Eyre 23',
' Wuthering Heights 56',
' War and Peace 60',
' Les Miserables 88',
'A Tale of Two Cities 75']
left alignment
用途に指定したい場合
>>> print [("%-20s%-4s"%(k, d[k])).strip() for k in d]
['Jane Eyre 23',
'Wuthering Heights 56',
'War and Peace 60',
'Les Miserables 88',
'A Tale of Two Cities75']