def median(a_list): step1 = sorted(a_list) if len(step1) % 2 == 0: height = len(step1) index1 = height / 2 first = step1(index) index2 = index1 - 1 second = first - 1 final = (first + second) / 2.0 return final else: length = len(step1) total = length + 1 half = total / 2 middle = half - 1 return step1(middle) It gives some error saying list object is not callable
try simplifying your code. spelling it out in more lines only helps to a certain extent.
that aside, your actual errors lie in your initiations of second and middle.
second should be
middle is unnecessary. the
half variable already contains the correct index
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.