title: Sort by Similarity instead of Alphabetically
body: <p>Sorting alphabetically, such as with <code>sorted()</code> in Python would yield the following:
  <code>
  a
  ab
  aa
  aab</code></p>
  
  <p>How might one go about achieving the following instead?
  <code>
  a
  aa
  ab
  aab</code></p>
  
  <p>More specifically, is there a conventional word for this, or is it otherwise a matter of implementing a custom algorithm to do so?</p>