title: Python sorting by multiple criteria
body: <p>I have a list where each element is of the form <code>[list of integers, integer]</code>.
  For example, an element of the list may look like this <code>[[1,3,1,2], -1]</code>. </p>
  
  <p>I want to sort a list containing the described type of elements by the following criteria:</p>
  
  <ol>
  <li><p>if the integer lists of two elements (i.e. <code>element[0]</code>) are of different length, the element with the smaller integer list is the smaller one.</p></li>
  <li><p>else if the integer lists are of the same length, the smaller element is that which has the smaller integer for the first integer which differs in the integer list of both elements. For example:</p>
  
  <p>[[1,1,99,100], -1] &lt; [[1,1,100,1], -1], because 99 &lt; 100. </p></li>
  <li><p>else if the integer lists are identical, the smaller element is the one with the smaller integer in <code>element[1]</code>.</p></li>
  </ol>
  
  <p>How would I write an approriate key function I could pass to sorted() or sort()?</p>