if not length % 2:
    return (sorts[length / 2] + sorts[length / 2 - 1]) / 2.0
return sorts[length / 2]
data_dict = defaultdict(list)
for el in data:
    data_dict[el[0]].append(el[1])
print([(key, median(val)) for key, val in list(data_dict.items())])
print(median([5, 2, 4, 3, 1]))
print(median([5, 2, 4, 3, 1, 6]))
[('Test', 300), ('Ram', 800), ('Sam', 700)]
3
3.5
How to find Median