Skip to content

Instantly share code, notes, and snippets.

@mindjiver
Created June 17, 2011 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mindjiver/1031764 to your computer and use it in GitHub Desktop.
Save mindjiver/1031764 to your computer and use it in GitHub Desktop.
Python list comprehesion qsort
def qsort(l):
if len(l) == 0:
return []
if len(l) == 1:
return l
# pick a random pivot
pivot = l[random.randint(0, len(l)-1)]
return (qsort([x for x in l if x < pivot]) +
[pivot] +
qsort([x for x in l if x > pivot]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment