Вы можете распечатать списки списков в виде таблиц, используя строки формата python:
# Input is expected as a list of list
rows = [
["TerritoryID", "TerritoryDescription", "RegionID"],
["1581", "Westboro", "1"],
["1730","Bedford","1"],
["1833","Georgetown","1"],
["2116","Boston","1"],
["2139","Cambridge","1"],
]
# First we get the max width of each column, like so:
max_col = list(max(map(len, x)) + 2 for x in list(map(list, zip(*rows))))
# Set some padding for the index column:
idx_pad = len(str(len(rows))) + 2
# Create a format string that will accept both values, and paddings:
s = "{:<{}}" + "{:<{}}" * len(max_col)
# Iterate the list of lists, printing each row:
for i, row in enumerate(rows):
if i == 0:
i = ""
c = row + max_col
c[::2] = row
c[1::2] = max_col
print(s.format(i, idx_pad, *c))
idx_pad = old_idx
, которые будут распечатаны:
TerritoryID TerritoryDescription RegionID
1 1581 Westboro 1
2 1730 Bedford 1
3 1833 Georgetown 1
4 2116 Boston 1
5 2139 Cambridge 1