Python 中的制表模块未提供所需的输出

Tabulate module in Python not giving the desired output

我在 Python 中使用制表列表:

import tabulate import tabulate
List4 = ['xyz-34t',  'abc-237', 'abc-eq1']
print tabulate(List4)

预期输出为

xyz-34t
abc-237
abc-eq1

实际输出:

x y z - 3 4 t
a b c - 2 3 7
a b c - e q 1

按照https://pypi.org/project/tabulate/的描述,你想要的可能是:

import tabulate

list4 = [['xyz-34t'], ['abc-237'], ['abc-eq1']]
print tabulate(list4)

回复你的评论:如果你的意思是上面的列表是 output of another function(你现在可以控制),因此如果你问如何把这个

['xyz-34t', 'abc-237', 'abc-eq1']

至此

[['xyz-34t'], ['abc-237'], ['abc-eq1']]

答案是(使用列表理解):

list = ['xyz-34t', 'abc-237', 'abc-eq1']
list_of_lists = [[x] for x in list]