Skip to content

Sorting · stretch

Merge sort

Write merge_sort(items) returning a new sorted list: split in half, merge_sort each half, then merge the two sorted halves.

A list of 0 or 1 items is already sorted — that is the base case.

Run adds print(merge_sort([5, 2, 9, 1, 5, 6])) after your code, to try it.

Stuck on the idea rather than the code? The Merge sort, and sorting by a key lesson walks through it.