How can I sort the player data based on the scores without using import Panda?
Here's my code:
player = {}
playerData = {}
def loadData():
fileHandle = open('Leaderboard.csv', 'r')
player.clear()
for line in fileHandle:
data = line[0:-1].split(",")
playerName = data[0]
playerScore = data[1]
playerPattern = data[2]
playerData = {}
playerData["Score"] = playerScore
playerData["Pattern"] = playerPattern
player[playerName] = playerData
fileHandle.close()
def leaderboard():
print("=========================================")
print("LEADERBOARD")
for k in player:
playerData = player[k]
playerScore = playerData["Score"]
playerPattern = playerData["Pattern"]
print(k + " - " + playerScore + " - " + playerPattern)
print("\n")
This is my CSV sample:
Liam 10 kdi
Joshua 50 djehfge
Patricia 25 fkris
I want my output to be like this:
Joshua - 50 - djehfge
Patricia - 25 - fkris
Liam - 10 - kdi
Don't mind the pattern, I just want to sort it based on the scores. Your help would be appreciated.