Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
def test_head():
    assert head([1]) == 1
    assert head([1,2]) == 1

    with pytest.raises(EmptyListError):
        head([])
Ejemplo n.º 3
0
def test_head():
    assert head([1]) == 1
    assert head([1, 2]) == 1

    with pytest.raises(EmptyListError):
        head([])