Skip to content

Instantly share code, notes, and snippets.

@julianbonilla
Created March 29, 2012 21:22
Show Gist options
  • Save julianbonilla/2243934 to your computer and use it in GitHub Desktop.
Save julianbonilla/2243934 to your computer and use it in GitHub Desktop.
Quicksort
#! /usr/bin/env python
def quicksort(list):
# Base case: single element list is sorted.
if list == []:
return list
pivot = list[0]
left = quicksort([i for i in list[1:] if i < pivot])
right = quicksort([i for i in list[1:] if i >= pivot])
return left + [pivot] + right
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment