title: merge sort code in python not working
body: <h2>Merge sort code in python</h2>
  
  <p>List index out of range error is flashing every time I try to run it.
  Don't know whats going on exactly.I'm pretty much new to python and algorithm stuff. Please help me to debug it.</p>
  
  <pre><code>def merge(m_list,first,middle,last):
      m_first = []
      m_last = []
      for each in range(first,middle):
          m_first.append(m_list[each])
  
      for each in range(middle,last+1):
          m_last.append(m_list[each])
  
      i=0
      j=0
      k=0
  
      while(i&lt;middle and j&lt;last-middle+1):
          if(m_first[i]&lt;m_last[j]):
              m_list[k] = m_first[i]
  
              i +=1
          else:
              m_list[k] = m_last[j]
  
              j +=1
          k +=1
  
      print(m_list)
  
      while(i&lt;middle):
          m_list[k] = m_first[i]
          k +=1
          i +=1
  
      while(j&lt;last-middle+1):
          m_list[k] = m_last[j]
          k +=1
          j +=1
  
  def merge_sort(m_list,first,last):
      if(first&lt;last):
          middle = int(abs((first+last)/2))
          merge_sort(m_list,first,middle)
          merge_sort(m_list,middle+1,last)
          merge(m_list,first,middle,last)
  
      return(m_list)
  
  
  
  merge_sort([1,4,6,2,3,5],0,5)
  </code></pre>
  
  <blockquote>
    <p>Here is the error shown by the code</p>
  </blockquote>
  
  <pre><code>Traceback (most recent call last):
    File "merge_sort.py", line 48, in &lt;module&gt;
      merge_sort([1,4,6,2,3,5],0,5)
    File "merge_sort.py", line 41, in merge_sort
      merge_sort(m_list,middle+1,last)
    File "merge_sort.py", line 40, in merge_sort
      merge_sort(m_list,first,middle)
    File "merge_sort.py", line 42, in merge_sort
      merge(m_list,first,middle,last)
    File "merge_sort.py", line 15, in merge
      if(m_first[i]&lt;m_last[j]):
  IndexError: list index out of range
  </code></pre>