Help in Median


Please help me on this


so [4,5,5,4] has a length of 4 and the following indexes: 0, 1, 2, 3

Which indexes are you using?


Sorry Stetim. Could not get your point.


mid1 and mid2 contain your indexes, for a list which has a length of 4, which indexes do this variable contain? And are this the middle two indexes?


but i tried by lis[mid1-1] and lis[mid2-1]. But the result is still a error


why would you do this instead of simply changing mid2 to x/2-1?

I can't address two issues at the same time. I first addressed the issue you where currently dealing with (using wrong indexes), and i can't guess what you already tried. (would be really impressive if i could)

now you get that 4 is returned instead of 4.5?

when you divide two integers:


You would expect that 4.5 is result. Except it is not, python will floor the number when dividing two integers

There is the catch: python only floors the number when dividing two integers, so we need to do something with a decimal number (float), how do you think this can be done?


Bingo. Did it. Thanks Stetim