defquick_sort(x, low, high):iflen(x)<=1or low >= high:return x
base, l, r = x[low], low, high
while l < r:while l < r and x[r]>= base:
r -=1
x[l]= x[r]while l < r and x[l]<= base:
l +=1
x[r]= x[l]
x[l]= base
quick_sort(x, low, l-1)
quick_sort(x, l+1, high)return x
defqsort(x):ifnot x:return[]
base = x[0]
less =[ele for ele in x[1:]if ele < base]
more =[ele for ele in x[1:]if ele >= base]return qsort(less)+[base]+ qsort(more)
defquick_sort(x, low, high):iflen(x)<=1or low >= high:return
stack =[low, high]while stack:
l, r = stack.pop(0), stack.pop(0)if l >= r:continue
i = l -1for j inrange(l, r):if x[j]< x[r]:
i +=1
x[i], x[j]= x[j], x[i]
x[i +1], x[r]= x[r], x[i +1]
stack.extend([l, i, i +2, r])