import random def QSort(a): if len(a) <= 1: return x = random.choice(a) A = [y for y in a if y < x] B = [y for y in a if y == x] C = [y for y in a if y > x] return QSort(A) + B + QSort(C)