def mergeSort( A ): if len(A)==1: #Base Case return else: middle = len(A)//2 #You could also do int(len(A)/2) #Create two temporary lists with COPIES of the two halves left = A[:middle] right = A[middle:] mergeSort(left) mergeSort(right) #Set up indices for where we are in each lists frontLeft = 0 frontRight = 0 frontMain = 0 # Copy data from L and R back in to A while frontLeft < len(left) and frontRight < len(right): if left[frontLeft] < right[frontRight]: A[frontMain] = left[frontLeft] frontLeft = frontLeft +1 else: A[frontMain] = right[frontRight] frontRight = frontRight +1 frontMain = frontMain + 1 # Checking which pile still has elements left while frontLeft < len(left): A[frontMain] = left[frontLeft] frontLeft += 1 frontMain += 1 while frontRight < len(right): A[frontMain] = right[frontRight] frontRight += 1 frontMain += 1 data = list(range(100)) import random random.shuffle(data) print(data) mergeSort(data) print(data)