Created
July 21, 2015 17:44
-
-
Save oskar-j/25b76fcf518078d3df2b to your computer and use it in GitHub Desktop.
Quicksort a list in Python language
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
def quicksort(arr): | |
""" Quicksort a list | |
:type arr: list | |
:param arr: List to sort | |
:returns: list -- Sorted list | |
""" | |
if not arr: | |
return [] | |
pivots = [x for x in arr if x == arr[0]] | |
lesser = quicksort([x for x in arr if x < arr[0]]) | |
greater = quicksort([x for x in arr if x > arr[0]]) | |
return lesser + pivots + greater |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment