PythiloLesson 11 of 32 · progress kept in this browser

Partition around a pivot for quicksort

Quicksort picks a pivot, moves smaller items before it and larger items after it, then sorts the two sides. The pivot is already in its final place after partitioning.

items = [7, 2, 9, 4]
pivot = items[-1]                     # 4
less = [x for x in items if x < pivot]
print(less)   # [2]
Your task

Write quicksort(items) returning a new sorted list. Partition into less, equal and greater lists around a pivot and recurse on less and greater.