Created
July 31, 2014 15:57
-
-
Save loisaidasam/df1899a23e8b1d874aaf to your computer and use it in GitHub Desktop.
Because there's no readily-available median() function in python?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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