#请问在程序最后加上print(" ") 为啥能分成三行,不加的话是一整行!
tableData = [['apple','orange','cherry','banana'],
['Alice','Bob','Cathy','David'],
['dog','cat','bird','duck']]
colWidth = [0] * len(tableData)
#print(str(len(colWidth)))
for i in range(len(colWidth)):
com = 0
for k in range(len(tableData[0])):
if len(tableData[i][k]) > com:
com = len(tableData[i][k])
colWidth[i] = com
for i in range(len(tableData[0])):
for k in range(len(colWidth)):
print(tableData[k][i].rjust(colWidth[k]),end=' ')
print('')
#程序运行结果
‘’‘’ apples Alice dogs
oranges Bob cat
cherries Carol moose
banana David goose ‘’‘’