Skip to content

Instantly share code, notes, and snippets.

@sebdah
Created August 4, 2014 07:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sebdah/a6ea9d3a8da49b1a10cd to your computer and use it in GitHub Desktop.
Save sebdah/a6ea9d3a8da49b1a10cd to your computer and use it in GitHub Desktop.
Quicksort implementation in Python
""" Quicksort implementation """
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