Skip to content

Instantly share code, notes, and snippets.

@mskims
Created May 14, 2017 12:35
Show Gist options
  • Select an option

  • Save mskims/3c582f2dd2532c5e051e5d4a37abedfe to your computer and use it in GitHub Desktop.

Select an option

Save mskims/3c582f2dd2532c5e051e5d4a37abedfe to your computer and use it in GitHub Desktop.
Python QuickSort
import random
def sort(ar):
if len(ar) < 2:
return ar
hand = ar.pop(random.randrange(len(ar)))
return sort([a for a in ar if a < hand]) + [hand] + sort([a for a in ar if a >= hand])
print(sort([1, 1, 1, 2]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment