Manolo Viso Romero Manolo Viso Romero - 22 days ago 8
Python Question

printing CSV in a different way

I need to print out a rankinglist from a csv file. I can get it printed out, that's not the problem but it will look like this:

[['team1', '100'], ['team2', '200'], ['team3', '300']]


I want it to print out like this:

team1, 100
team2, 200
team3, 300


I found that my knowledge of Python/ english language isn't high enough to understand what is being explained on other stackoverflow topics here so I have to ask you to be as simple as possible
this is the piece of code that I'm using

def read():
a = open('casus.csv','r')
Areader = csv.reader(a)
a = []
for row in Areader:
if len (row) != 0:
a = a + [row]
print(a)

Answer

if you have exactly two elements in each list, this should work.

def read():
    a = open('casus.csv','r')
    Areader = csv.reader(a)
    for row in Areader:
        if len(row != 0):
            print(row[0]+","+row[1])
Comments