From: Raymond Hettinger Date: Wed, 26 Mar 2014 09:00:54 +0000 (-0700) Subject: Broaden the early-out test for nsmallest and nlargest X-Git-Tag: v3.5.0a1~2021 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8f2420c94b350cf37b0ac06bda5539f754c1b469;p=python Broaden the early-out test for nsmallest and nlargest --- diff --git a/Lib/heapq.py b/Lib/heapq.py index d615239b94..d52cd715e1 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))