Skip to content

Instantly share code, notes, and snippets.

@Makistos
Created June 16, 2016 06:42
Show Gist options
  • Save Makistos/844a07d013b71ea6b74d3dea41324a23 to your computer and use it in GitHub Desktop.
Save Makistos/844a07d013b71ea6b74d3dea41324a23 to your computer and use it in GitHub Desktop.
Calculating the median from a list in Python. #python
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