【发布时间】:2016-12-06 07:54:58
【问题描述】:
我知道如何对齐表格中的所有字段:
r=["this is my text of line1",
"and this was one more line",
"another line of text to display"]
import re
splitter = "\s+"
columnstotal = []
for i in range(0,len(r)):
#remove splitter
columns = re.split(splitter, r[I])
#keep splitter
columns = re.split('(' + splitter + ')', r[i])
columnstotal.append(columns)
并使用 .format() 再次显示列
但是如何只对齐 2 列:
第 2 列(右对齐)+ 第 4 列(左对齐)?
预期输出:
this is| my |text of line1
and this| was |one more line
another line| of |text to display
【问题讨论】:
-
请提供更多输入数据,以及您希望在输出中看到的确切结果。
-
另外,作为一个旁注,如果你想要
r的一部分,你不会在Python中对r的长度做一个数字for:你可以简单地做@987654326 @ -
@jsbueno,我更新了我的问题
-
@jsbueno,你还在吗?
标签: python list python-3.x alignment multiple-columns