Last active
December 18, 2015 22:09
-
-
Save nharrell04/5852681 to your computer and use it in GitHub Desktop.
return x[w]
TypeError: list indices must be integers, not float
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(some_list): | |
x = sorted(some_list) | |
if len(x)%2 == 0: | |
q = len(x)/2 | |
t = x[q] | |
u = x[(q-1)] | |
v = (t+u)/2.0 | |
return v | |
else: | |
w = (len(x)/2)+.5 | |
return x[w-1] | |
print median([4,5,5,4,1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment