# 快速排序
def main(ary):
# D&C思想:基线条件
if len(ary) < 2:
return ary
else:
base = ary[0]
left = [i for i in ary[1:] if i <= base]
right = [i for i in ary[1:] if i > base]
return main(left) + [base] + main(right)
ary = [1, 34, 22, 54, 66, 22, 12, 25, 78, 91, 41, 1, 34, 22, 54, 66, 22, 12, 25, 78, 91, 41, 1, 34, 22, 54, 66, 22, 12, 25, 78, 91, 41]
res = main(ary)
print(res)
"""
[1, 1, 1, 12, 12, 12, 22, 22, 22, 22, 22, 22, 25, 25, 25, 34, 34, 34, 41, 41, 41, 54, 54, 54, 66, 66, 66, 78, 78, 78, 91, 91, 91]
"""
原文:https://www.cnblogs.com/pywjh/p/14943398.html