Exemplo n.º 1
0
def test_tail():
    assert tail([1]) == []
    assert tail([1,2]) == [2]
    assert tail([1,2,3]) == [2, 3]

    with pytest.raises(EmptyListError):
        tail([])
Exemplo n.º 2
0
def test_tail():
    assert tail([1]) == []
    assert tail([1, 2]) == [2]
    assert tail([1, 2, 3]) == [2, 3]

    with pytest.raises(EmptyListError):
        tail([])
Exemplo n.º 3
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
Exemplo n.º 4
0
def pairs(xs):
    """Return a sequence of tuples representing all pairs of values in a list."""
    if not xs:
        return []
    return zip(xs, tail(xs))