Python-3.x:如何在相等的列中打印多个列表?

标签 python python-3.x list

我对 python 很陌生,我正在尝试输出多个列表,一个在另一个下,在列中,但我不知道。

我当前的输出是:

Name, Count, Correct, Incorrect, Accuracy, Total

Abena 3 3 0 100 45

Malcolm 1 1 0 100 1

Jane 1 1 0 100 20

Liz 1 1 0 100 10

Andy 1 0 1 0 20

Sandip 0 0 0 0 0

如何将数字分成单独的列?

当前要打印的代码是:

CoinFile = open("CoinCount.txt", "r")
    print("Name, Count, Correct, Incorrect, Accuracy, Total")
    for record in VolunteersToSort:
            print(record[0] + " " + record[1]+ " " + record[2] + " " + record[3] + " " + record[4] + " " + record[5] )

文件内容:

['Abena', '3', '3', '0', '100', '45']
['Malcolm', '1', '1', '0', '100', '1']
['Jane', '1', '1', '0', '100', '20']
['Andy', '1', '0', '1', '0', '20']
['Sandip', '0', '0', '0', '0', '0']
['Liz', '1', '1', '0', '100', '10']

最佳答案

header = ['Name', 'Count', 'Correct', 'Incorrect', 'Accuracy', 'Total']
my_list = [
    ['Abena', '3', '3', '0', '100', '45'], 
    ['Malcolm', '1', '1', '0', '100', '1'],
    ['Jane', '1', '1', '0', '100', '20'],
    ['Andy', '1', '0', '1', '0', '20'],
    ['Sandip', '0', '0', '0', '0', '0'], 
    ['Liz', '1', '1', '0', '100', '10']
]    
print("{: >10} {: >10} {: >10} {: >10} {: >10} {: >10}".format(*header))
for row in my_list:
    print("{: >10} {: >10} {: >10} {: >10} {: >10} {: >10}".format(*row))

您的输出将为:

      Name      Count    Correct  Incorrect   Accuracy      Total 
     Abena          3          3          0        100         45 
   Malcolm          1          1          0        100          1 
      Jane          1          1          0        100         20 
      Andy          1          0          1          0         20 
    Sandip          0          0          0          0          0 
       Liz          1          1          0        100         10 

您可以根据需要编辑列长度。这里使用 10。

关于Python-3.x:如何在相等的列中打印多个列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53670132/

相关文章:

list - SGI slist和C++ 11 forward_list有什么区别?

python - 我正在尝试将 CNN 与非图像数据一起使用

python - 从其中包含 return <value> 语句的生成器中产生

python:不同包下同名的两个模块和类

function - 如何打印函数头,包括名称、参数和文档字符串?

python - Tkinter - 使用绑定(bind)动态调整框架大小

Python。需要确定连接是从本地机器建立的吗?

python - 文件上传后返回对象id

c++ - 我需要链接什么库才能在 clang++ 中使用 std::list ?

r - 如何创建一个空列表?