Print multiple lists each in a column

Asked

Viewed 39 times

0

I have five lists that were extracted from an Excel table in CSV. I would like to know how I do to print them in the terminal next to each other, I believe it can be done with a loop for, but I didn’t get the syntax right.

a = []
b = []
c = []
d = []
e = []

dataset = open ("Teste_Plotagem.csv","r")

for line in dataset:
    line = line.strip()
    A,B,C,D,E = line.split(";")
    a.append(A)
    b.append(B)
    c.append(C)
    d.append(D)
    e.append(E)

dataset.close()

print(a)
print(b)
print(c)
print(d)
print(e)

1 answer

1


a = ["Pedro", "Ricardo", "Renato", "Sonia", "Rosana"]
b = ["Analista", "Financeiro", "Controlador", "Produção", "Logística"]
c = [4000, 3100, 5000, 1900, 1400]

x = 0
for i in a:
    print("{}\t\t\t{}\t\t\t{}".format(a[x], b[x], c[x]))
    x+=1

Output:

Pedro           Analista            4000
Ricardo         Financeiro          3100
Renato          Controlador         5000
Sonia           Producaoo           1900
Rosana          Logistica           1400

How about? You can also create a single list:

a = ["Pedro", "Ricardo", "Renato", "Sonia", "Rosana"]
b = ["Analista", "Financeiro", "Controlador", "Produção", "Logística"]
c = [4000, 3100, 5000, 1900, 1400]

lst = []

x = 0
for i in a:
    temp_lst = [a[x], b[x], c[x]]
    lst.append(temp_lst)
    x+=1

for line in lst:
    print(line)

Output:

['Pedro', 'Analista', 4000]
['Ricardo', 'Financeiro', 3100]
['Renato', 'Controlador', 5000]
['Sonia', 'Produção', 1900]
['Rosana', 'Logística', 1400]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.