Can't figure out what's wrong - 'list' object not callable


#1



def median(my_list):
    temp_list = sorted(my_list)
    length = len(my_list)
    index = int(length / 2)
    
    if length == 1:
        return temp_list[0]
    
    if length % 2 == 1:
        return temp_list(index)
    else:
        return float((temp_list(index) + temp_list(index - 1)) / 2)


#2

You're using the wrong syntax for indexing sometimes. For instance: you're using temp_list(index), whilst you should be using temp_list[index]


#3

Oh man I feel dumb, thanks!


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.