#6.11.1
tableData = [['apples', ' oranges', 'cherries', 'banana'], ['Alice', 'Bob', 'Carol', 'David'], ['dogs', 'cats', 'moose', 'goose']] def printTable(lists): # convert lists to talbes Long = [] for littlelist in lists: for word in littlelist: longs = len(word) Long.append(longs) k = Long[0] for i in Long: if i > k: k = i y = len(lists[0]) for x in range(y): if x != 0 : print() for v in lists: if lists.index(v) == 0: print(v[x].rjust(k, ' '), end=' ') else: print(v[x].ljust(k, ' '), end=' ') printTable(tableData)
笔者的方法仍与书中有所不同,但已经是笔者现在所能做的做好的方法,希望再更深入地学习Python之后,能够做到和书中一样。