title: Custom Python list sorting
body: <p>I was refactoring some old code of mine and came across of this:</p>
  
  <pre><code>alist.sort(cmp_items)
  
  def cmp_items(a, b):
      if a.foo &gt; b.foo:
          return 1
      elif a.foo == b.foo:
          return 0
      else:
          return -1
  </code></pre>
  
  <p>The code works (and I wrote it some 3 years ago!) but I cannot find this thing documented anywhere in the Python docs and everybody uses <code>sorted()</code> to implement custom sorting. Can someone explain why this works?</p>