Created
January 11, 2021 11:06
-
-
Save corehello/500dce6d9575f7be63af47de0807b9ef to your computer and use it in GitHub Desktop.
quicksort in python - most understandable
This file contains 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 qsort(arr): | |
if len(arr) <= 1: | |
return arr | |
else: | |
# construct array with [(values bigger than pivot), pivot, (values smaller than pivot)] | |
return qsort([x for x in arr[1:] if x > arr[0]]) + \ | |
[arr[0]] + \ | |
qsort([x for x in arr[1:] if x <= arr[0]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment