1
我想创建一个函数,输出一个矩阵,其中包含列表中的每个项目在一个单独的行与中间的行。我得到的唯一结果是报价('')。我不懂为什么。我认为我把它全部正确地设置以输出需要的东西,但是必须缺少一些东西?Python中输出错误?
我在我的代码下面包含了一些例子。
def show_table(table):
table=[]
s=[[str(e) for e in row] for row in table]
lens= [max(map(len, col)) for col in zip(*s)]
fmt= '\t'.join('{{:{}}}'.format(x) for x in lens)
table= [fmt.format(*row) for row in s]
return '\n'.join(table)
show_table([['A','BB'],['C','DD']])
输出:
“| A | BB | \ n | C | DD | \ N”
打印(show_table([[ 'A', 'B-B'],[ 'C', 'D-D']])) 输出:
| A | BB | | C | DD |
我怎么会把之间的界限?您的解决方案确实解决了输出问题! –
我已经更新了答案,但我不确定你想要完成什么,我希望这给你一个大致的想法来建立。 –
我需要在两侧放置一条线,其间的空格| a | bb | –