Python quicksort - List comprehension vs Recursion (partition routine)
问题 I watched the talk Three Beautiful Quicksorts and was messing around with quicksort. My implementation in python was very similar to c (select pivot, partition around it and recursing over smaller and larger partitions). Which I thought wasn't pythonic . So this is the implementation using list comprehension in python. def qsort(list): if list == []: return [] pivot = list[0] l = qsort([x for x in list[1:] if x < pivot]) u = qsort([x for x in list[1:] if x >= pivot]) return l + [pivot] + u