Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove sort side effect in thinkstats.Trim #2

Closed
GoogleCodeExporter opened this issue Apr 3, 2015 · 1 comment
Closed

Remove sort side effect in thinkstats.Trim #2

GoogleCodeExporter opened this issue Apr 3, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

Done.  Thanks for the suggestion.

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

  • Changed state: Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant