Skip to content

Sorting · routine

Insertion sort

Write insertion_sort(items) that sorts the list in place — change the list you were given, return nothing.

Walk left to right. Take each item and slide it left past every bigger item before it, like sorting cards in your hand.

Run adds print(cards) after your code, to try it.

Stuck on the idea rather than the code? The Sorting lesson walks through it.