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

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

li = [6,1,5,2,4,3]
print(qsort(li, reverse=True))

Embed on website

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