Created
June 16, 2016 06:42
-
-
Save Makistos/844a07d013b71ea6b74d3dea41324a23 to your computer and use it in GitHub Desktop.
Calculating the median from a list in Python. #python
This file contains hidden or 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(l): | |
sortedl = sorted(l) | |
mid = (len(sortedl) -1) // 2 | |
if (len(sortedl)) % 2: | |
return (sortedl[mid] + sortedl[mid+1]) / 2.0 | |
else: | |
return sortedl[mid] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment