I have a txt file that looks like this:
Raj,Joy:9,8,1
Smith,John:8
Campbell,Michelle:5,7,9
NOTE: There is no empty lines between the lines of text in the text file
I want to output each result of each person in descending numerical order, e.g.
Campbell,Michelle:9
Raj,Joy:9
Raj,Joy:8
Smith,John:8
Campbell,Michelle:7
etc.
The code I have so far is this:
data = src.readlines()
for line in data:
record = line.split(':')
scoreList = record[1].split(',')
# Add name to fileRecord
for n in scoreList:
fileRecord.append(record[0])
# Two dimensional list created, each item is one set of scores
fileScores.append(scoreList)
where src is the text file. The main problem posed for me is if I invoke .sort() on sortList I lose the order and so cannot match each score with its corresponding name. If I were to create a dictionary the problem posed is outputting the sorted data individually as sorting
{"Raj,Joy":[9,8,1],etc}
would not sort it by each individual score that "Raj,Joy" got, but I cant split the list because then I would have duplicate keys.