title: How to add numbers given as a list of tuples given in the form: ('name', number)
body: <p>def highest_n_scores(scores, n = 5):</p>
  
  <p>Each player plays the game some number of times, each time resulting in a tuple (name, score) for how much that player scored in the game. Given all games played as a list of such tuples, add up the n highest scores for each individual player as the total score for that player. Create and return a list that contains tuples (name, total) for the players and their total scores, sorted in ascending order by name. If some player has played fewer than n times, just add up the scores of whatever games that player has played.</p>
  
  <p>The code is below but I wanted to know if there is a more efficient way of doing this and it also doesn't seem to work using the tester.</p>
  
  <pre><code>def highest_n_scores(scores, n):
  
      bill = sorted([p for (t,p) in scores if t == 'bill'])
      jack = sorted([p for (t,p) in scores if t == 'jack'])
      sheldon = sorted([p for (t,p) in scores if t == 'sheldon'])
      tina = sorted([p for (t,p) in scores if t == 'tina'])
      amy = sorted([p for (t,p) in scores if t == 'amy'])
      bob = sorted([p for (t,p) in scores if t == 'bob'])
  
      scoreBill = sum(bill[-n:])
      scoreJack = sum(jack[-n:])
      scoreSheldon = sum(sheldon[-n:])
      scoreTina = sum(tina[-n:])
      scoreAmy = sum(amy[-n:])
      scoreBob = sum(bob[-n:])
  
      return sorted([('bill', scoreBill), ('jack', scoreJack), ('sheldon', scoreSheldon), ('tina', scoreTina), ('amy', scoreAmy), ('bob', scoreBob)])
  </code></pre>
  
  <p>I get the correct result, but the tester for all values however, the tester I was given to test the code says my answer is wrong.</p>
  
  <p>list : </p>
  
  <pre><code>[('bill', 10), ('jack', 6), ('sheldon', 3), ('tina', 2), ('amy', 3), ('sheldon', 6), ('tina', 7), ('jack', 2), ('bob', 3), ('bob', 4), ('bill', 3), ('bill', 9), ('sheldon', 5), ('amy', 2), ('jack', 7), ('sheldon', 5), ('sheldon', 7), ('bill', 1), ('bill', 9), ('sheldon', 5), ('bill', 2), ('bill', 6), ('jack', 6), ('bob', 4), ('tina', 5), ('sheldon', 4), ('sheldon', 2), ('amy', 6), ('bob', 7), ('jack', 2), ('bob', 5), ('sheldon', 9), ('jack', 5), ('amy', 9), ('bob', 7), ('tina', 6), ('tina', 2), ('amy', 7), ('jack', 10), ('tina', 4), ('bob', 5), ('jack', 10), ('bob', 7), ('jack', 5), ('amy', 4), ('amy', 8), ('bob', 4), ('bill', 8), ('bob', 6), ('tina', 6), ('amy', 9), ('bill', 4), ('jack', 2), ('amy', 2), ('amy', 4), ('sheldon', 1), ('tina', 3), ('bill', 9), ('tina', 4), ('tina', 9)] when n = 3
  </code></pre>
  
  <p>list return : </p>
  
  <pre><code>[('amy', 26), ('bill', 28), ('bob', 21), ('jack', 27), ('sheldon', 22), ('tina', 22)]
  </code></pre>