我在對齊結果值時遇到了問題。如何在Python中對齊結果值
Alist = ["1,25,999",
"123.4,56.7890,13.571",
"1,23.45,6,7.8"]
c = 0
while c < len(Alist):
r = 0
tokens = Alist[c].split(',')
while r < len(Alist[c].split(',')):
if '.' in tokens[r]:
print "%7.2f" %float(tokens[r]), " ",
else :
print "%3d" %float(tokens[r]), " ",
r += 1
print
c += 1
我想打印如
1 25 999
123.40 56.79 13.57
1 23.45 6. 7.80
但不知何故,它是印刷
1
25
999
123.40
56.79
13.57
1
23.45
6
7.8
,我想不出有什麼不對我的編碼。