def merge_sort(array): if len(array) <= 1: return array middle = len(array) // 2 left = merge_sort(array[:middle]) right = merge_sort(array[middle:]) return merge(left, right) def merge(left, right): result = [] i = 0 j = 0 while i < len(left) and j < len(right): if left[i] <= right[j]: result.append(left[i]) i += 1 else: result.append(right[j]) j += 1 result += left[i:] result += right[j:] return result if __name__ == "__main__": array = [12, 11, 13, 5, 6, 7, 1, 2, 3, 4] print(merge_sort(array))