Skip to content

Instantly share code, notes, and snippets.

@muromtsev
Last active October 12, 2023 17:52
Show Gist options
  • Save muromtsev/75baa92b8f14bcf513c4ad099e5145bb to your computer and use it in GitHub Desktop.
Save muromtsev/75baa92b8f14bcf513c4ad099e5145bb to your computer and use it in GitHub Desktop.
Quick sort
def quicksort(arr):
if len(arr) < 2:
return arr
else:
pivot = arr[0]
less = [i for i in arr[1:] if i < pivot]
greater = [i for i in arr[1:] if i > pivot]
return quicksort(less) + [pivot] + quicksort(greater)
print(quicksort([10, 5, 2, 3])) # [2, 3, 5, 10]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment