【问题标题】:Turn list into table in Python [duplicate]在Python中将列表转换为表格[重复]
【发布时间】:2014-03-26 23:13:26
【问题描述】:

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

进入:

Abe     200

Lindsay 180

Rachel  215

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

【问题讨论】:

  • 和你要求“矩阵”的方式一样:stackoverflow.com/questions/22673924/…
  • 我不清楚你想要的最终形式。那些是字符串吗?字符串之间的空白行是所需输出的一部分吗?您希望第二列如何对齐?
  • 你整个下午都在问同样的问题。您在这里得到的出色答案是否有问题:stackoverflow.com/questions/22670097/…
  • 这是作业,他是新手?

标签: python list 2d tuples


【解决方案1】:
students = [("Abe", 200), ("Lindsay", 180), ("Rachel" , 215)]
for student in students:
    print(*student, sep='\t')  # python 3

for student in students:
    print '\t'.join(str(i) for i in student)  # python 2

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-10
    • 2014-07-14
    • 2014-04-03
    • 2017-03-24
    • 2018-10-14
    • 2017-07-31
    • 1970-01-01
    相关资源
    最近更新 更多