Skip to content

Instantly share code, notes, and snippets.

@pervognsen
Created March 3, 2010 10:38
Show Gist options
  • Save pervognsen/320514 to your computer and use it in GitHub Desktop.
Save pervognsen/320514 to your computer and use it in GitHub Desktop.
def all_equal(iterable):
it = iter(iterable)
try:
first = it.next()
return all(x == first for x in it)
except StopIteration:
return True
def median(seq, key=None):
sorted_seq = sorted(seq, key=key)
return sorted_seq[len(seq) / 2]
def partition(seq, pivot, key=lambda x: x):
left, middle, right = [], [], []
for x in seq:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment