pythoncook book上有个3行代码实现的quicksort,该成随机版。。
很pythonic
#!/usr/bin/env python from random import randint def qsort(L): l=len(L) if l<=1: return L else: r=randint(0,l-1) return qsort([lt for lt in L[:r]+L[r+1:] if lt<L[r]])+L[r:r+1]+qsort([gt for gt in L[:r]+L[r+1:] if gt>=L[r]]) print qsort([3,23,4,66,1,34,2])
非常简洁