算法导论第三版,9.3
import random
import math
#returns the number of elements that smaller than x
#the input is A[p...r] inclusive in the convention of book, 1 <= p <= r <= n
#in Python, to represent A[p...r], we should use a[p-1:r]
def partition(a,p,r,x):
low = [m for m in a if m < x]
high = [m for m in a if m > x]
a[p-1:r] = low + [x] +