[EMAIL PROTECTED] wrote: > John Doty: > > Yes. The efficient exact algorithms for this problem use *partial* > > sorts. The Forth one from the FSL is of this class (although I know of > > two better ones for big arrays). But it's tough to beat the efficiency > > of the approximate histogram-based method the Python stats module > > implements. > > The usual way to compute a true median with Python may be: > > def median(inlist): > newlist = sorted(inlist) > index = len(newlist) // 2 > if len(newlist) % 2: > return newlist[index] > else: > return (newlist[index] + newlist[index-1]) / 2.0 > [snip]
no sort() is needed to calculate the median of a list. you just need one temp var. -- http://mail.python.org/mailman/listinfo/python-list