Skip to content

Instantly share code, notes, and snippets.

@rolangom
Created March 4, 2023 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rolangom/6acd5a92b085f5b4ce78e243c5f3db33 to your computer and use it in GitHub Desktop.
Save rolangom/6acd5a92b085f5b4ce78e243c5f3db33 to your computer and use it in GitHub Desktop.
Quick sort implementation in python using recursive calls and for comprehension
def quicksort(array):
if len(array) == 0:
return array
pivot = array[0]
rest = array[1:]
smallers = quicksort([x for x in rest if x < pivot])
biggers = quicksort([x for x in rest if x >= pivot])
return [*smallers, pivot, *biggers]
# for olders version of python
# return smallers + [pivot] + biggers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment