Median "TypeError: 'list' object is not callable"


#1



here is my code

def median(numbers):
    sort = sorted(numbers)
    print sort
    result = 0
    length = len(sort)
    mid = length/2
    if length == 1:
        sort(0)
    elif length % 2 == 0:
        result = [sort(mid) + sort(mid - 1)]/2.0
    else:
        result = sort((length-1)/2)
    return result
sequence = [6,8,13,5,14]
print median(sequence)

it gives me error below:

[5, 6, 8, 13, 14]
Traceback (most recent call last):
  File "python", line 15, in <module>
  File "python", line 12, in median
TypeError: 'list' object is not callable

please tell me where am I wrong?


#2

We cannot sort a value unless it is a list item. Technically, sort([0]) is valid, but trivial. Just return the value at index [0].

Edit. Clap trap. I just realized my own mistake. But, you can set result to sort[0] and be done.

I haven't run this so try that change and see what happens.


#3

Thank you so much .....