title: Python3 - change pattern A to B using lowest weight
body: <p>So i have path A and B and weights of objects in path, for example:</p>
  <pre><code>A = [5, 4, 2, 1, 3, 8, 7, 6, 9]
  B = [2, 3, 4, 1, 9, 7, 8, 6, 5]
  </code></pre>
  <p>and weights, for example:</p>
  <pre><code>W = {1:1000, 2:500, 3:200, 4:400, 5:700, 6:250, 7:100, 8:50, 9:900}
  </code></pre>
  <p>and I want to replace A to B with using lowest weight,
  for example if we want to replace 6 and 8, the used weight is: 50+250=300</p>
  <p>what algorithm of sorting should i use etc?</p>
  <p>example:</p>
  <pre><code> IN [5, 4, 2, 1, 3, 8, 7, 6, 9] swap 4,2 weight = 400+500=900 
      [5, 2, 4, 1, 3, 8, 7, 6, 9] swap 5,2 weight=700+500=1200 
      [2, 5, 4, 1, 3, 8, 7, 6, 9] swap 8,7 weight=50+100=150
      [2, 5, 4, 1, 3, 7, 8, 6, 9] swap 3,5 weight=200+7000=900 
      [2, 3, 4, 1, 5, 7, 8, 6, 9] swap 5,9 weight=700+900=1600
      [2, 3, 4, 1, 9, 7, 8, 6, 5] == B, sum = 900+1200+150+900+1600=4750
  </code></pre>