예제 #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
예제 #2
0
파일: test_basics.py 프로젝트: drkjam/funpy
def test_head():
    assert head([1]) == 1
    assert head([1,2]) == 1

    with pytest.raises(EmptyListError):
        head([])
예제 #3
0
def test_head():
    assert head([1]) == 1
    assert head([1, 2]) == 1

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