我在 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]