Skip to content

Instantly share code, notes, and snippets.

@kbendick
Created March 8, 2016 20:08
Show Gist options
  • Save kbendick/31b6be3cf9379d3cd3fe to your computer and use it in GitHub Desktop.
Save kbendick/31b6be3cf9379d3cd3fe to your computer and use it in GitHub Desktop.
Simple implementation of quicksort in python
import random
R = random.Random(42)
def qsort(L):
if len(L) < 2: return L
i = R.randrange(len(L)) # Just some random index in the list.
return qsort([x for x in L if x < L[i]]) + [x for x in L if x == L[i]] + qsort([x for x in L if x > L[i]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment