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
Add nlargest() and nsmallest() to heapq. #40369
Comments
This patch adds a function that encapsulates a principal |
Logged In: YES Revised the patch to also include nsmallest(). Note, the API intentionally does not provide default values of |
Logged In: YES +1 on nlargest(). -0 on nsmalles(), because it has radically different time and |
Logged In: YES For many values of n, nsmallest() still makes substantially Here are the comparison counts for a list with a 1000 random 8649 sort 999 1 nlargest 1088 5 nlargest 1238 10 nlargest 1487 20 nlargest 2052 40 nlargest 2953 80 nlargest 4516 160 nlargest 6835 320 nlargest 9177 640 nlargest 9742 1000 nlargest P.S. Using itertools, the nsmallest() can be made to run at def nsmallest(iterable, n):
"""Find the n smallest elements in a dataset.
|
Logged In: YES Taking this one back off Tim's busy plate. If I deluded myself with the attached tests, he can give me a |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: