Skip to content

Instantly share code, notes, and snippets.

@loisaidasam
Created July 31, 2014 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loisaidasam/df1899a23e8b1d874aaf to your computer and use it in GitHub Desktop.
Save loisaidasam/df1899a23e8b1d874aaf to your computer and use it in GitHub Desktop.
Because there's no readily-available median() function in python?
def median(data):
if not data:
return
length = len(data)
sorts = sorted(data)
if length % 2:
return sorts[length/2]
return 1.0 * (sorts[length/2-1] + sorts[length/2]) / 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment