yxakuo / thinkstats

Automatically exported from code.google.com/p/thinkstats
0 stars 0 forks source link

Remove sort side effect in thinkstats.Trim #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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.

Original issue reported on code.google.com by gbre...@gmail.com on 7 Sep 2012 at 2:47

GoogleCodeExporter commented 9 years ago
Done.  Thanks for the suggestion.

Original comment by allendow...@gmail.com on 19 Jun 2013 at 2:37