0

I've used a draft code and adapted it to suit my code but I don't know how to split the data. The question might seem a vague so I'll try to be help by saying what I want. My code:

import csv
with open("scores.csv") as csv_data:
    reader=csv.reader(csv_data,delimiter=",")
    number_sorted=sorted(reader,key=lambda x:int(x[0]),reverse=True)
    print(number_sorted)

I get the output:

[['25356767', 'tom'], ['443388', 'jin'], ['6744', 'trev'], ['4666', 'ryan'], 
['2445', 'jones'], ['536', 'sue'], ['34', 'bob'], ['8', 'hera'], ['1', 
'bill'], ['0', 'v']]

but I want the print to look like this so it looks like a leader board:

`[['25356767', 'tom'],
['443388', 'jin'], 
['6744', 'trev'], 
['4666', 'ryan'], 
['2445', 'jones'],
['536', 'sue'], 
['34', 'bob'],
['8', 'hera'],
['1', 'bill'],
['0', 'v']]`

I hope that explains my question.

Kevin
  • 74,910
  • 12
  • 133
  • 166
Ray
  • 1
  • 1
  • 4

1 Answers1

0

Can't do that, sorry.

What you're asking to do is, essentially, altering the way the console outputs lists. Simpler (and, probably, prettier) would be to define a function to pretty print the lists.

If you did something like:

def pretty(inlist):
  for score, name in inlist:
    print name.rjust(10) +"|  " +score

Then it would print every line in a pretty format.

Jakob Lovern
  • 1,301
  • 7
  • 24