Created
May 14, 2017 12:35
-
-
Save mskims/3c582f2dd2532c5e051e5d4a37abedfe to your computer and use it in GitHub Desktop.
Python QuickSort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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