快排思路:
1、取一个元素p(第一个元素),使元素p归位
2、列表被p分成两部分,左边都比p小,右边都比p大
3、递归完成排序
def quick_sort(list1):
if len(list1) < 2:
return list1
else:
mid_pivot = list1[0]
less_before_mid_pivot = [i for i in list1[1:] if i <= mid_pivot]
bigger_after_pivot = [i for i in list1[1:] if i > mid_pivot]
finally_list = quick_sort(less_before_mid_pivot) + [mid_pivot] + quick_sort(bigger_after_pivot)
return finally_list
print(quick_sort([2, 4, 6, 7, 1, 2, 5]))