Skip to content

Instantly share code, notes, and snippets.

@kayluhb
Last active August 29, 2015 14:11
Show Gist options
  • Save kayluhb/fa335378b2b8a5333da0 to your computer and use it in GitHub Desktop.
Save kayluhb/fa335378b2b8a5333da0 to your computer and use it in GitHub Desktop.
Quick Sort python
def quick_sort(lst):
if len(lst) <= 1:
return lst
low, middle, high = [], [], []
pivot = lst[0]
for num in lst:
if num < pivot:
low.append(num)
elif num > pivot:
high.append(num)
else:
middle.append(num)
low = quick_sort(low)
high = quick_sort(high)
return low + middle + high
print(quick_sort([0, 30, -40, 300, 10, 4, 34, -6]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment