mirror of
https://github.com/python/cpython.git
synced 2025-11-25 12:44:13 +00:00
Broaden the early-out test for nsmallest and nlargest
This commit is contained in:
parent
b0e6951193
commit
8f2420c94b
1 changed files with 2 additions and 2 deletions
|
|
@ -197,7 +197,7 @@ def nlargest(n, iterable):
|
|||
|
||||
Equivalent to: sorted(iterable, reverse=True)[:n]
|
||||
"""
|
||||
if n < 0:
|
||||
if n <= 0:
|
||||
return []
|
||||
it = iter(iterable)
|
||||
result = list(islice(it, n))
|
||||
|
|
@ -215,7 +215,7 @@ def nsmallest(n, iterable):
|
|||
|
||||
Equivalent to: sorted(iterable)[:n]
|
||||
"""
|
||||
if n < 0:
|
||||
if n <= 0:
|
||||
return []
|
||||
it = iter(iterable)
|
||||
result = list(islice(it, n))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue