Skip to contentKEEP THE CRAFTTHE SANCTUARY

Partition and Quick Sort

Sort a list with quick sort, using the Lomuto partition around the last value.

The problem

Implement quick_sort(values). Return a new list with the same values in ascending order, and leave values itself unchanged. values may be empty and may contain repeated or negative numbers. Do not call sorted or list.sort: write quick sort yourself.

Starter code

def quick_sort(values):
    pass

Public examples

  1. values = [4, 1, 4, 2]gives[1, 2, 4, 4]
  2. values = [5, 3, 1]gives[1, 3, 5]

Solving it in the practice book needs an active paid plan.

Open it in the practice book
One thought at a time.