def merge_sort(list,i,j,new_list): ''' (list,int,int) -> list modifies and sorts 'list' showing steps and returns list >>> merge_sort([3,2,-4,6,5], 0, len([3,2,-4,6,5]),[0]*len([3,2,-4,6,5])) ''' if j-i <= 1: return [] n = (i+j)//2 merge_sort(list,i,n,new_list) merge_sort(list,n,j,new_list) merge(list,i,j,new_list) return new_list def merge(list,i,j,new_list): ''' (list,int,int,list) -> None merges two sub lists in an order ''' n = (i+j)//2 i1 = i j1 = n i2 = n j2 = j while i1 < j1 and i2 < j2: if list[i1] < list[i2] : new_list[i] = list[i1] i1 = i1 + 1 else: new_list[i] = list[i2] i2 = i2 + 1 i = i + 1 while i1 < j1: new_list[i] = list[i1] i1 = i1 + 1 i = i + 1 while i2 < j2: new_list[i] = list[i2] i2 = i2 + 1 i = i + 1 return new_list

when I run it and type:

>>> merge_sort([3,2,-4,6,5], 0, len([3,2,-4,6,5]),[0]*len([3,2,-4,6,5])) [-4, 3, 2, 6, 5]

I don't get any errors, and I can't seem to find the problem here. Please help!

also, the merge() function seems to be working fine:

>>> list = [2,6,9,3,6,8] >>> merge(list,0,len(list),[0]*len(list)) [2, 3, 6, 6, 8, 9]

This post has been edited by **macosxnerd101**: 23 August 2014 - 01:51 PM

Reason for edit:: Renamed title to be more descriptive