I doing some algorithm reviews and am soliciting opinions on my implementation of the Merge Sort in Python.
Anything from readability to optimization is fair game.
In particular, I am wondering if accessing the elements of a list using
pop(0) somehow slows things down. I am doing this because I am not aware of a good way to peek into the last for the last element.
import math def merge(left, right): merge_result =  while (len(left) > 0 and len(right) > 0): if left > right: merge_result.append(right.pop(0)) else: merge_result.append(left.pop(0)) while (len(left)): merge_result.append(left.pop(0)) while (len(right)): merge_result.append(right.pop(0)) return merge_result def merge_sort(array_to_be_sorted): if len(array_to_be_sorted) < 2: return array_to_be_sorted middle = math.floor(len(array_to_be_sorted) / 2) left = array_to_be_sorted[0:middle] right = array_to_be_sorted[middle:] return merge(merge_sort(left),merge_sort(right))