def q_sort(arr):
if len(arr)<2:
return arr pivot = arr[0] less = [x for x in arr[1:] if x <= pivot]
more = [x for x in arr[1:] if x > pivot]
return q_sort(less) + [pivot] + q_sort(more) print(q_sort(a))
python新手看到这个,感觉python确实很灵活。
2024-03-29 12:42:34
def q_sort(arr):
if len(arr)<2:
return arr pivot = arr[0] less = [x for x in arr[1:] if x <= pivot]
more = [x for x in arr[1:] if x > pivot]
return q_sort(less) + [pivot] + q_sort(more) print(q_sort(a))
python新手看到这个,感觉python确实很灵活。