PythiloLesson 9 of 32 · progress kept in this browser

Insert each item into a sorted prefix

Insertion sort keeps the left part of the list sorted. Each new item slides left past larger neighbours until it reaches its place, like sorting a hand of cards.

hand = [3, 7, 9, 4]
# 4 moves past 9 and 7, then stops after 3
Your task

Write insertion_sort(items) returning a new sorted list, without calling sorted or list.sort, and without changing items.