title: Mistake in my implementation of merge sort?
body: <p>Here is my implementation of merge sort</p>
  <pre><code>    lis=list()
      lis=[9,0,5,1,8,3,7,2,6,4]
  
      def merge(lis,l,m,r):
          i=l
          j=m
          n1=m-1-l
          n2=r-m
          temp=list()
          while(i&lt;=n1 and j&lt;=n2):
              if(lis[i]&lt;lis[j]):
                  temp.append(lis[i])
                  i+=1
              else:
                  temp.append(lis[j])
                  j+=1
          while(i&lt;=n1):
              temp.append(lis[i])
              i+=1
          while(j&lt;=n2):
              temp.append(lis[j])
              j+=1
          for k in range(len(temp)):
              lis[l+k]=temp[k]
  
      def mergesort(lis,l,r):
          if(l&lt;r):
              m=(l+r)//2
              mergesort(lis,l,m)
              mergesort(lis,m+1,r)
              merge(lis,l,m,r)
  
      mergesort(lis,0,9)
      print(lis)
  </code></pre>
  <p>this is the output : [0, 5, 8, 3, 9, 1, 7, 2, 6, 4]
  does sort for some recursions but hen bonks to death
  is there a problem in math used please help</p>
  <p>cannot figure out what is wrong with my code</p>