title: Sorting by attributes that can be None
body: <p>Let's say I have a list of items I want to sort: <code>items = [ item1, item2, item3 ]</code>. The attribute I want to use to sort them is <code>item.data.value</code>, so I'd normally go:</p>
  
  <pre><code>sorted(items, key=attrgetter('data.value'))
  </code></pre>
  
  <p>And that'd work just fine. However, <code>data</code> can actually be <code>None</code> so obviously I couldn't access <code>value</code>.</p>
  
  <p>How do you usually deal with scenarios like this?</p>
  
  <p>PS: neither <a href="https://stackoverflow.com/questions/12971631/sorting-list-by-an-attribute-that-can-be-none">this question</a> nor <a href="https://stackoverflow.com/questions/39085672/sorting-by-multiple-values-that-can-be-none">this one</a> helped.</p>