Broaden the early-out test for nsmallest and nlargest

This commit is contained in:
Raymond Hettinger 2014-03-26 02:00:54 -07:00
parent b0e6951193
commit 8f2420c94b
1 changed files with 2 additions and 2 deletions

View File

@ -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))