Skip to content

Instantly share code, notes, and snippets.

@nharrell04
Last active December 18, 2015 22:09
Show Gist options
  • Save nharrell04/5852681 to your computer and use it in GitHub Desktop.
Save nharrell04/5852681 to your computer and use it in GitHub Desktop.
return x[w] TypeError: list indices must be integers, not float
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