title: Efficient way to sort an array with a condition
body: <p>I have a numpy array:</p>
  
  <pre><code>a = np.array(["dcba", "abc", "bca", "bcda", "tda", "a"])
  </code></pre>
  
  <p>Now I have a vectorized Levenshtein edit distance function which measures distance of given string with given array, for example, for string <code>ab</code>:</p>
  
  <pre><code>l_distv("ab", a)
  </code></pre>
  
  <p>returns:</p>
  
  <pre><code>array([3, 1, 3, 4, 3, 1])
  </code></pre>
  
  <p>I'd like to sort an array in a way so that any element with edit distance smaller than 2 moves to first positions, while the rest are moved behind them <b>without changing their order</b>. So result would be:</p>
  
  <pre><code>array(["abc", "a", "dcba", "bca", "bcda", "tda"])
  </code></pre>
  
  <p>I've done this, but it's pretty ugly, I assume there is a more efficient way. </p>