def partition(f, li):
    if not len(li):
        return [],[]
    x, *xs = li 
    ys, zs = partition(f, xs)
    if f(x): return [x, *ys], zs 
    return ys, [x, *zs]

def qsort(li):
    if not len(li):
        return []
    p, *xs = li
    ys, zs = partition(lambda x: x <= p, xs)
    return [*qsort(ys), p, *qsort(zs)]

li = [5,4,1,3,2,0]
f = lambda x: x <= 2
print(partition(f, li))
print(qsort(li))

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: