defqsort(l):ifnot l:
return []
pivot = l[0]
lesser = qsort([item for item in l[1:] if item < pivot])
greater = qsort([item for item in l[1:] if item >= pivot])
return lesser + [pivot] + greater
归并排序
defgsort(l):
length = len(l)
if length == 1:
return l
mid = length / 2
first = gsort(l[0:mid])
second = gsort(l[mid:])
temp = []
while first and second:
if first[0] < second[0]:
temp.append(first[0])
del first[0]
else:
temp.append(second[0])
del second[0]
return temp + first + second