When creating median function, why do I get the error: "‘list’ object is not callable"?

When I run the following code in Learn Python 2’s lesson called 15. median, I’m receiving an error. Any advice? Here’s my code:

def median(list_input):
 list_input_sorted = sorted(list_input)
 if len(list_input_sorted) % 2 == 0:
   #if even, average the middle two numbers
   first = len(list_input_sorted) / 2
   second = first + 1
   my_sum = list_input_sorted[first] + list_input_sorted(second)
   return my_sum / 2
 else:
   #if odd, take the median
   this_index = len(list_input_sorted) / 2
   return list_input_sorted[this_index]

The parens make this an invocation of a function. Swap in square brackets so second is a subscript, not an argument.

1 Like