#m = [45,23,3,56,89,12,7,0,89,32,125,67]
m = [5,4,8,7,3,4]
def q(a):
if len(a) <= 1:
return a
#p = a[len(a) // 2] # центральный элемент массива
p = a[0]
left = [x for x in a if x < p] # меньшие опорного - влево
middle = [x for x in a if x == p]
right = [x for x in a if x > p]
print('a', a, a[0])
# print('l', left, 'm', middle, 'r', right)
#
# print('p', p)
return q(left) + middle + q(right)
print(q(m))
# Если опорным взять первый элемент
# a = [5,4,8,7,3,4]
# [4,3,4][5][8,7]
# a = [4,3,4,5,8,7]
# [4,3,4][5][8,7]
# [[3][4,4][] [5] [[7][8][]]