Skip to content

Instantly share code, notes, and snippets.

@corehello
Created January 11, 2021 11:06
Show Gist options
  • Save corehello/500dce6d9575f7be63af47de0807b9ef to your computer and use it in GitHub Desktop.
Save corehello/500dce6d9575f7be63af47de0807b9ef to your computer and use it in GitHub Desktop.
quicksort in python - most understandable
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