如何在Python中打印长度不同的列表的表格
我该如何从两个长度不同的列表中打印出一个表格(每个列表作为一列)呢?
举个例子:
>>> l1=['Cat', 'Dog', 'Gorilla', 'Ladybug']
>>> l2=['Cat', 'Dog']
>>> print_chart(l1, l2)
Cat Cat
Dog Dog
Gorilla
Ladybug
使用 rjust 可能会很有帮助。
1 个回答
6
for a, b in izip_longest(l1, l2, fillvalue=''):
print "{0:20s}\t{1:20s}".format(a, b)