title: Python: sort an array of dictionaries with custom comparator?
body: <p>I have the following Python array of dictionaries:</p>
  
  <pre><code>myarr = [ { 'name': 'Richard', 'rank': 1 },
  { 'name': 'Reuben', 'rank': 4 },
  { 'name': 'Reece', 'rank': 0 },
  { 'name': 'Rohan', 'rank': 3 },
  { 'name': 'Ralph', 'rank': 2 },
  { 'name': 'Raphael', 'rank': 0 },
  { 'name': 'Robin', 'rank': 0 } ]
  </code></pre>
  
  <p>I'd like to sort it by the rank values, ordering as follows: 1-2-3-4-0-0-0.</p>
  
  <p>If I try:</p>
  
  <pre><code>sorted_master_list = sorted(myarr, key=itemgetter('rank'))
  </code></pre>
  
  <p>then the list is sorted in the order 0-0-0-1-2-3-4. </p>
  
  <p>How can I define a custom comparator function to push zeroes to the bottom of the list? I'm wondering if I can use something like <a href="http://pythonadventures.wordpress.com/tag/operator/">methodcaller</a>. </p>