python - 将 Python 2D 矩阵/列表转换为表格

标签 python list matrix 2d tuples

我怎样才能改变这个:

students = [("Abe", 200), ("Lindsay", 180), ("Rachel" , 215)]

进入此:

Abe     200
Lindsay 180
Rachel  215

编辑:这应该适用于任何大小的列表。

最佳答案

使用string formatting :

>>> students = [("Abe", 200), ("Lindsay", 180), ("Rachel" , 215)]
>>> for a, b in students:
...     print '{:<7s} {}'.format(a, b)
...
Abe     200
Lindsay 180
Rachel  215

关于python - 将 Python 2D 矩阵/列表转换为表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22670097/

相关文章:

java - java中如何只抓取二维矩阵的某一行?

python - 有效删除不同行之间包含重复元素的行

python - 我可以将多线程应用于 python 中的计算密集型任务吗?

python - 在 Python 中使用嵌套列表

C++ 矩阵乘法不产生正确的输出

c - 二维字符数组中的排序列

python - Twisted Python - 如果 deferred 超出范围,它会被解雇吗?

python - 在 python 中对列表或列表列表进行字符串化并将其转换回原始形式的问题

python - 排序字符串列表 - 外部列表中的内部列表

python - 如何有效地创建遍历 python 中的大量列表?