title: Read high scores from text file and rank
body: <p>I have a maths program that is scoring  players and entering their name and score in to a text file.</p>
  
  <p>I can get the score out of the text file but cant work out how to identify each part: name as string and score as int.</p>
  
  <p>It is entered in to the file like this:</p>
  
  <pre><code>playername: 8
  </code></pre>
  
  <p>The code that enters the player name and score to the text file is: (I have set score as a global variable and it is being pulled from an earlier function.</p>
  
  <pre><code># write score to text document
  def scores():
      score = Pname + ": " +str(points)
      scoreFile = open("score.txt", "a")
      scoreFile.write(score + "\n")
      scoreFile.close()
      print("Your scores have been saved to the high score chart.\n")
  close()
  </code></pre>
  
  <p>The multiple ways I have tried to get it out just give me the data. I'm struggling to split it in to name and score and then rank it in descending order by the score.</p>
  
  <pre><code>def highscore():
  # --------------------------------------------
  # sort scores from text file here
  try:
      scores = open("score.txt", "r")
      for line in scores.readlines():
          line_parts = line.split(": ")
          if len(line_parts) &gt; 1:
              line_parts = line_parts[-1].split("\n")
              score = line_parts[0]
          print(sorted(score))
  except Exception:
      pass
  # --------------------------------------------
  close()
  </code></pre>
  
  <p>This just shows the scores as follows:</p>
  
  <pre><code>['7']
  ['4']
  ['9']
  ['1']
  </code></pre>
  
  <p>What I need it to look like is:</p>
  
  <pre><code>['Player 1: 9']
  ['Player 2: 7']
  ['Player 3: 4']
  ['Player 4: 1']
  </code></pre>