title: Sorting a dictionary of tuples in Python
body: <p>I know there's tonnes of questions on python sorting lists/dictionaries already, but I can't seem to find one which helps in my case, and i'm looking for the most efficient solution as I'm going to be sorting a rather large dataset.</p>
  
  <p>My data basically looks like this at the moment:</p>
  
  <pre><code>a = {'a': (1, 2, 3), 'b': (3, 2, 1)}
  </code></pre>
  
  <p>I'm basically creating a word list in which I store each word along with some stats about it (n, Sigma(x), Sigma(x^2) )</p>
  
  <p>I want to sort it based on a particular stat. So far I've been trying something along the lines of:</p>
  
  <pre><code>b = a.items()
  b.sort(key = itemgetter(1), reverse=True)
  </code></pre>
  
  <p>I'm not sure how to control which index it is sorted based on when its effectively a list of tuples of tuples? I guess I effectively need to nest two itemgetter operations but not really sure how to do this.</p>
  
  <p>If there's a better data structure I should be using instead please let me know. Should I perhaps create a small class/struct and then use a lambda function to access a member of the class?</p>
  
  <p>Many Thanks</p>