Median-Finding Function


I really cannot see what's wrong with my code. Please explain if you do.


m_index = (len(sort/2) - 0.5

I assume that you subtract 0.5 to get to the next lower integer. But in Python 2 integer division will always return an integer.

For example:

print (3 / 2)
# this will print 1

So you can just use len(sort)/2 or you can use len(sort) / 2.0 to get the result as a float and than substract 0.5.


OH! That would make a big difference. THANKS, and WOW what a generally useful fact!


I just saw that you also have median = added/2, the same principle applies here.


RESOLVED, thanks to @eveat!

You can also use float(5/2) to procure the result of 5/2.0