标签:normal 输出 ott orange print ati apple ext otto
#-*- coding:utf-8 -*-
# 要求输出如下:
# apples Alice dogs
# dranges Bob cats
# cherries Carol moose
# banana David goose
tableData=[['apples','oranges','cherries','banana'],
['Alice','Bob','Carol','David'],
['dogs','cats','moose','goose']]
def printTable(data):
colWidths=[0]*len(data)
for y in range(len(data[0])):
for x in range(len(data)):
if colWidths[x] < len(data[x][y]):
colWidths[x]=len(data[x][y])
for y in range(len(data[0])):
for x in range(len(data)):
if x==0:
print(data[x][y].rjust(colWidths[x]),end=' ')
else:
print(data[x][y].ljust(colWidths[x]),end=' ')
print()
printTable(tableData)
标签:normal 输出 ott orange print ati apple ext otto
原文地址:http://blog.51cto.com/2884868/2069900