//
is floor division:>>> 5//2 2so if there are odd number of elements you want to return
srt[mid+1]
(on line 6)With even number of elements median should be the mean of the middle two numbers (i.e. the true division of the middle 2 elements)-
mid
and mid+1
, not mid-1
med = (srt[mid] + srt[mid+1]) / 2
Also because of using floor division you don't need to explicitly convert to int on line 8 (but this is just a note)
that said, you better add argument to median function, instead of using global variable
lst
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs