So I've imported a text file into python. The file is a database storing users names and scores. It currently prints in pretty much the same format as the original file. I've split each line into two parts: name and score. I've managed to sort the data alphabetically, and am now trying to sort it from highest to lowest, but have no idea how??
file = open("classj.txt") classj = (file.readlines()) for line in sorted(classj): classj = (line.rstrip()) classa = (classj.split("-")) score = (classa) name = (classa) print(name,"-",score)
EMILY - 7 JEMMA - 9 LEO - 6 MARCO - 8 RILEY - 5
Any ideas how to make the code sort the file so the highest score (JEMMA) is displayed first, and the lowest score (RILEY) is displayed last?