I've built a function to calculate median (as the name indicates).
The function receives a list of ints, for instances [4,5,5,4] and should output 4,5.
The code:
def median(lst):
lst.sort()
a=int(len(lst)/2)
if len(lst) % 2 == 0:
med=float((lst[a]+lst[a-1])/2)
else:
med=lst[a]
return med
print(median([4,5,5,4]))
This works fine when using Python 3.x but not in Python 2.x. What am i doing wrong?