def sq(l,s,e): i = s j = e-1 tmp = l[i] while i <j: while i<j and l[j]>tmp: j -= 1 l[i] = l[j] while i<j and l[i]<=tmp: i += 1 l[j] = l[i] l[i] = tmp return i def s(l,s,e): po = sq(l,s,e) sq(l,s,po) sq(l,po+1,e) l = [49,38,65,97,76,13,27] s(l,0,len(l)) print l