15. median stuck



Oops, try again. median([4, 5, 5, 4]) returned 4 instead of 4.5

to return 4.5

def median(aList):
    medIndex= (len(renewed)-1)/2
    if (medIndex/0.5)%2==0:
    return output


Why on this line:

if (medIndex/0.5)%2==0:

not check if the list has a odd or even numbers of items? That is currently not what you are doing. To check if a list is odd or even simple do:

if len(renewed) %2 == 1: #list is odd

Also, the len of the list divided by two will always return the middle item if the list has a odd number of items, or if the list has a even number of items, the right one of the two middle items. So, len /2 - 1 will return the left item of the middle item.

for example, if this is your list:


the len is 4, 4 / 2 = 2. At index two, there is 5. So at index 1 there 4. Which are the two middle items, which you need