次の方法で、プログラムの出力の一部を印刷しています。
a=[1,2,3]
b=[10,20,30]
c=[101,201,301]
d=[1010,2010,3010]
results = {'a':a,'b':b,'c':c,'d':d}
print str("First result: ").center(20), str("Second result: ").center(20), str("Third result: ").center(20), str("Fourth result: ").rjust(20)
print
for i in xrange(len(results)):
print repr(float("{0:.2f}".format(results['a'][i]))).center(20),\
repr(float("{0:.2f}".format(results['b'][i]))).center(20),\
repr(float("{0:.2f}".format(results['c'][i]))).center(20),\
repr(float("{0:.2f}".format(results['d'][i]))).center(20)
次の素敵な出力が得られます。
First result: Second result: Third result: Fourth result:
1.0 10.0 101.0 1010.0
2.0 20.0 201.0 2010.0
3.0 30.0 301.0 3010.0
しかし、定義されていない結果が多数あるとしましょう。どうすれば同じ種類の出力を記述できるでしょうか?
ありがとう。