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 = [1,3,2,5,4,6]
print(partition(lambda x: x%2, li))
print(qsort(li, reverse=True))
To embed this project on your website, copy the following code and paste it into your website's HTML: