title: How to get all orderings of a list such that the list is equal to another list?
body: <p>I have lists A and B, which can have duplicates, for example:</p>
  
  <pre><code>A = ['x', 'x', 7]
  B = [7, 'x', 'x']
  </code></pre>
  
  <p>Now I want all index permutations that permute list B into list A:</p>
  
  <pre><code>[1, 2, 0]    # because [B[1], B[2], B[0]] == A
  [2, 1, 0]    # because [B[2], B[1], B[0]] == A
  </code></pre>
  
  <p>Is there are way to achieve this without iterating over all possible permutations?
  I already use</p>
  
  <pre><code>import itertools
  for p in itertools.permutations(range(len(B))):
      if A == permute(B,p):
  </code></pre>
  
  <p>to iterate over all possible permutations and check for the ones I want, but I want to have the right ones faster.</p>