def median(lst): """ Return the median of lst. """ # make a copy of lst, so we don't change (sort) the original. # The problem didn't say you had to do this. mylst = lst[:] mylst.sort() n = len(mylst) if n%2 == 1: # odd length return mylst[(n-1)/2] else: # even length return (mylst[n/2 - 1] + mylst[n/2]) / 2.0 print median( [32,10,54,23,21] ) print median( [42,13,80,85,22,43] )