diff options
author | Raymond Hettinger <python@rcn.com> | 2014-03-26 02:00:54 -0700 |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2014-03-26 02:00:54 -0700 |
commit | 8f2420c94b350cf37b0ac06bda5539f754c1b469 (patch) | |
tree | 41a9441a4b315dbeaa4401d4e0d979573002a594 /Lib/heapq.py | |
parent | Merge #20145 backport: delete whatsnew entry. (diff) | |
download | cpython-8f2420c94b350cf37b0ac06bda5539f754c1b469.tar.gz cpython-8f2420c94b350cf37b0ac06bda5539f754c1b469.tar.bz2 cpython-8f2420c94b350cf37b0ac06bda5539f754c1b469.zip |
Broaden the early-out test for nsmallest and nlargest
Diffstat (limited to 'Lib/heapq.py')
-rw-r--r-- | Lib/heapq.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Lib/heapq.py b/Lib/heapq.py index d615239b946..d52cd715e12 100644 --- a/Lib/heapq.py +++ b/Lib/heapq.py @@ -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)) |