def quicksort(a):
 n = len(a)
 if (n <= 1):
  return a
 else:
  from random import randrange
  pivot = a.pop(randrange(n))
  lesser = quicksort([x for x in a if (x < pivot)])
  greater = quicksort([x for x in a if (x >= pivot)])
  return ((lesser + [pivot]) + greater)

def quicksort ( a ) : n = len ( a ) if ( n <= 1 ) : return a else : from random import randrange pivot = a . pop ( randrange ( n ) ) lesser = quicksort ( [ x for x in a if ( x < pivot ) ] ) greater = quicksort ( [ x for x in a if ( x >= pivot ) ] ) return ( ( lesser + [ pivot ] ) + greater )
quicksort implementation in python note: this algo uses o(n) extra space to compute quicksort .