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 3Think before coding
It takes about n squared steps in the worst case, yet it is fast on nearly sorted data and stable: equal items keep their order because an item stops at the first neighbour that is not larger. Work through the example by hand before changing the starter. Decide what should happen for an empty input, a single value and a repeated value where those cases apply. The checks use several inputs so a hard-coded answer cannot stand in for the rule.
Your task
Write insertion_sort(items) returning a new sorted list, without calling sorted or list.sort, and without changing items.
The explanation opens here once every check passes.