Help in Median


#1

Please help me on this


#2

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

Which indexes are you using?


#3

Sorry Stetim. Could not get your point.


#4

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?


#5

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


#6

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:

9/2

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?


#7

Bingo. Did it. Thanks Stetim


#8