Mean, median, and mode

Scott David Daniels Scott.Daniels at Acm.Org
Mon Dec 6 22:21:56 CET 2004


How about:

def median(lst):
	lst = sorted(lst)
	inner = lst[(len(lst) - 1) // 2 : (len(lst) + 2) // 2]
	if len(inner) > 1:
		return sum(inner) / 2.
	else:
		return inner[0]


--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list