title: Sort and rank list python and write back to MySQL using python
body: <p>I'm reading values from MySQL using python then sorting a list. I need to then rank the list and write it back to MySQL. My code is</p>
  
  <p>Get list</p>
  
  <pre><code>cursor.execute ("SELECT winnings, user, rank FROM round_lb WHERE r_id = 5")
  round_test = cursor.fetchall()
  </code></pre>
  
  <p>returns</p>
  
  <pre><code>((90L, 70L, 0L), (17L, 1L, 0L), (25L, 78L, 0L))
  </code></pre>
  
  <p>Sort list (so the highest winnings column is first)</p>
  
  <pre><code>print sorted(round_test, reverse =True)
  [(90L, 70L, 0L), (25L, 78L, 0L), (17L, 1L, 0L)]
  </code></pre>
  
  <p>I now want to assign a value to the rank field so 90 is rank1, 25 rank2 and 17 rank3 etc...</p>
  
  <p>Which is where I get stuck.. does anyone know a simple way way to rank them in python... so I can then write them back to MySQL...</p>