def test_tail(): assert tail([1]) == [] assert tail([1,2]) == [2] assert tail([1,2,3]) == [2, 3] with pytest.raises(EmptyListError): tail([])
def test_tail(): assert tail([1]) == [] assert tail([1, 2]) == [2] assert tail([1, 2, 3]) == [2, 3] with pytest.raises(EmptyListError): tail([])
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 pairs(xs): """Return a sequence of tuples representing all pairs of values in a list.""" if not xs: return [] return zip(xs, tail(xs))