title: Merging three lists together
body: <p>For fun, I am trying to implement k way merge sort where k =3. I do not have trouble with calling mergesort recursively but I am trying to merge three lists together but I am not getting a sorted list. The basic idea is that I compare the first element of every list and if it is the smallest I append it to a list. I repeat the process for all the arrays.</p>
  
  <pre><code>def three_merge(a,b,c):
      i =0
      j =0
      k=0
      list = []
      while(i &lt; len(a) or j &lt; len(b) or k &lt; len(c)):
          while(a[i] &lt;= b[j] and a[i] &lt;= c[k]):
              list.append(a[i])
              i=i+1
              print i
          while(b[j] &lt;= a[i] and b[j] &lt;= c[k]):
              list.append(b[j])
              j=j+1
              print j
          while(c[k] &lt;= a[i] and c[k] &lt;= b[j]):
              list.append(c[k])
              k=k+1
              print k
     return list    
  
  a = [1,2]
  b = [-5,10]
  c = [-11, 100]
  print three_merge(a,b,c)                            
  </code></pre>