title: Sorting and Grouping Nested Lists in Python
body: <p>I have the following data structure (a list of lists)</p>
  
  <pre><code>[
   ['4', '21', '1', '14', '2008-10-24 15:42:58'], 
   ['3', '22', '4', '2somename', '2008-10-24 15:22:03'], 
   ['5', '21', '3', '19', '2008-10-24 15:45:45'], 
   ['6', '21', '1', '1somename', '2008-10-24 15:45:49'], 
   ['7', '22', '3', '2somename', '2008-10-24 15:45:51']
  ]
  </code></pre>
  
  <p>I would like to be able to</p>
  
  <ol>
  <li><p>Use a function to reorder the list so that I can group by each item in the list. For example I'd like to be able to group by the second column (so that all the 21's are together) </p></li>
  <li><p>Use a function to only display certain values from each inner list. For example i'd like to reduce this list to only contain the 4th field value of '2somename' </p></li>
  </ol>
  
  <p>so the list would look like this </p>
  
  <pre><code>[
       ['3', '22', '4', '2somename', '2008-10-24 15:22:03'], 
       ['7', '22', '3', '2somename', '2008-10-24 15:45:51']
  ]
  </code></pre>