【发布时间】:2014-12-09 21:08:25
【问题描述】:
我正在尝试打印一个像表格一样的二维列表,我在这里找到了一段代码: Pretty print 2D Python list
但我不明白它是如何工作的,谁能给我解释一下?
s = [[str(e) for e in row] for row in matrix]
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]
print '\n'.join(table)
【问题讨论】:
-
你不明白什么?列出理解?地图?压缩?论据解包?加入?格式?