title: sorting a nested dictionary with lists in python
body: <p>I am trying to sort a dictionary containing lists.  For example, if I have this dictionary:</p>
  
  <pre><code>a = {'q': {3: [4, 2, 7]}, 'a': {1: [5, 45, 11]}, 'e': {23: [11, 45, 2]}}
  </code></pre>
  
  <p>I want the output after sorting to be:</p>
  
  <pre><code>[(e, {23:[11,45,2}]), (a, {1:[5,45,11]}), (q,{3,[4,2,7]})] 
  </code></pre>
  
  <p>I am actually sorting in reverse, using the first item in the list as the key for the sort. </p>
  
  <p>In the event that the first items of two lists are identical, like above, I sort for the string associated with the list (main key) in alphabetical order.</p>
  
  <p>I am not sure if I can get the output of tuples with dictionary in it as I am sorting for that the list in that dictionary.</p>
  
  <p>I have tried this code:</p>
  
  <pre><code>sorted((x,b.items(), key=lambda x:[1][2]) for x,b in a.items())
  </code></pre>
  
  <p>It raised an error for invalid syntax, and I can't figure out what's wrong.</p>