title: Sort a list of dictionaries by values with some items missing
body: <p>I have a dict of lists like this:</p>
  
  <pre><code>a = [
     {'p': 3, 'id': 'ab1'},
     {'p': 10, 'id': 'ab2'},
     {'p': 5, 'id': 'ab3'},
     {'p': 8, 'id': 'ab4'},
     {'id': 'ab5'}
  ]
  </code></pre>
  
  <p>I want to sort <code>a</code> by the value of <code>p</code>. If dict doesn't has <code>p</code>, put it behind.
  I tried this way:</p>
  
  <pre><code>print sorted(a, key=lambda i: i.get('p'))
  </code></pre>
  
  <p>and got result:</p>
  
  <pre><code>[{'id': 'ab5'}, {'p': 3, 'id': 'ab1'}, {'p': 5, 'id': 'ab3'}, {'p': 8, 'id': 'ab4'}, {'p': 10, 'id': 'ab2'}]
  </code></pre>
  
  <p>but want to get is:</p>
  
  <pre><code>[{'p': 3, 'id': 'ab1'}, {'p': 5, 'id': 'ab3'}, {'p': 8, 'id': 'ab4'}, {'p': 10, 'id': 'ab2'},{'id': 'ab5'}]
  </code></pre>
  
  <p>What can I do to get the correct result with easier way?</p>