Export to GitHub

thinkstats - issue #2

Remove sort side effect in thinkstats.Trim


Posted on Sep 7, 2012 by Massive Wombat

in the thinkstats.py module, the Trim function creates a (documented) side effect of sorting the sequence that is passed in as a parameter. Instead of using the sort() method on the list, use the sorted builtin to sort the values into another array.

Existing code --

def Trim(t, p=0.01): t.sort() n = int(p * len(t)) t = t[n:-n] return t

Proposed code --

def Trim(t, p=0.01): sorted_t = sorted(t) n = int(p * len(sorted_t)) return sorted_t[n:-n]

Of course, the comments and documentation would have to be updated as well.

Comment #1

Posted on Jun 19, 2013 by Happy Rhino

Done. Thanks for the suggestion.

Status: Done

Labels:
Type-Defect Priority-Medium