array = [29,99,27,41,66,28,44,78,87,19,31,76,58,88,83,97,12,21,44] q = lambda l: q([x for x in l[1:] if x <= l[0]]) + [l[0]] + q([x for x in l if x > l[0]]) if l else [] print(q(array))