def qsort(xs): """Sort a list using the quick sort algorithm.""" if not xs: return [] else: h = head(xs) ts = tail(xs) smaller = [n for n in ts if n <= h] larger = [n for n in ts if n > h] result = qsort(smaller) + [h] + qsort(larger) return result
def test_head(): assert head([1]) == 1 assert head([1,2]) == 1 with pytest.raises(EmptyListError): head([])
def test_head(): assert head([1]) == 1 assert head([1, 2]) == 1 with pytest.raises(EmptyListError): head([])