title: Merge sort implementation a struggle due to way variables are stored
body: <p>I have some C++ and Python experience but definitely I have been struggling with this one. I get the concept of merge sort but I don't understand how Python stores the values. I focused on sorting only <code>[11, 26, 9]</code> for the sake of dividing this monster into smaller pieces.</p>
  <p>To be more concrete, in the output below, what happens after this line:
  1 1 2 (i j k) before 2nd while loop? Which loop does Python execute to get to the last line of the attached output? My main confusion is about [11] ending up between 9 and 26. Which loop did cause that?</p>
  <pre><code>OUTPUT:
  [11, 26, 9] left;
  [15, 17, 77] right;
  [11, 26, 9, 15, 17, 77] myList after dividing by 2;
  [11] left;
  [26, 9] right;
  [11, 26, 9] myList after dividing by 2;
  [26] left;
  [9] right;
  [26, 9] myList after dividing by 2;
  [26] left;
  [9] right;
  [26, 9] myList at zero;
  1 length of right;
  1 length of left;
  0 0 0 (i j k) before if loop;
  [9, 9] myList at else;
  [26] left before 2nd while loop;
  [9] right before 2nd while loop;
  0 1 1  (i j k) before 2nd while loop;
  [9, 26] myList 2nd while loop i;
  [11] left;
  [9, 26] right;
  [11, 26, 9] myList at zero;
  2 length of right;
  1 length of left;
  0 0 0 (i j k) before if loop;
  [9, 26, 9] myList at else;
  [11] left;
  [9, 26] right;
  [9, 26, 9] myList at zero;
  2 length of right;
  1 length of left;
  0 1 1 (i j k) before if loop;
  [9, 26, 9] myList at if;
  [11] left before 2nd while loop;
  [9, 26] right before 2nd while loop;
  1 1 2  (i j k) before 2nd while loop;//WHAT HAPPENS HERE NEXT WITH [11]?
  [11] left after 2nd while loop j;
  [9, 26] right after 2nd while loop j;
  [9, 11, 26] myList 2nd while loop j;
  </code></pre>
  <pre><code>import scipy.io as sio, math as m, numpy as np, sympy as sym, scipy as sp
  
  def mergeSort(myList):
      if len(myList) &gt; 1:
          mid = len(myList) // 2
          left = myList[:mid]
          print(left, &quot;left&quot;)
          right = myList[mid:]
          print(right, &quot;right&quot;)
          print(myList, &quot;myList after dividing by 2&quot;)
          mergeSort(left)
          mergeSort(right)
          i, j, k = 0, 0, 0
       
          while i &lt; len(left) and j &lt; len(right):
              print(left, &quot;left&quot;)
              print(right,&quot;right&quot;)
              print(myList, &quot;myList at zero&quot;)
              print(len(right), &quot;length of right&quot;)
              print(len(left), &quot;length of left&quot;)
              print(i, j, k, &quot;(i j k) before if loop&quot;)
              # ---------------------------------------------------------------------    
              if left[i] &lt; right[j]:
                  print(myList, &quot;myList at if&quot;)
                  myList[k] = left[i]
                  i += 1
              else:
                  myList[k] = right[j]
                  print(myList, &quot;myList at else&quot;)
                  j += 1
             
              k += 1
              # -------------------------------------------------------------------------
          print(left, &quot;left before 2nd while loop&quot;)
          print(right, &quot;right before 2nd while loop&quot;)
          print(i, j, k, &quot; (i j k) before 2nd while loop&quot;)
          # ------------------------------------------------------------------------
          while i &lt; len(left):
              myList[k] = left[i]
              i += 1
              k += 1
              print(myList, &quot;myList 2nd while loop i&quot;)
              
          while j &lt; len(right):
              myList[k] = right[j]
              j += 1
              k += 1
              print(left, &quot;left after 2nd while loop j&quot;)
              print(right, &quot;right after 2nd while loop j&quot;)
              print(myList, &quot;myList 2nd while loop j&quot;)
              
  myList = [11,26,9,15,17,77]
  mergeSort(myList)
  print(myList)
  </code></pre>