From 8f2420c94b350cf37b0ac06bda5539f754c1b469 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Wed, 26 Mar 2014 02:00:54 -0700 Subject: [PATCH] Broaden the early-out test for nsmallest and nlargest --- Lib/heapq.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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)) -- 2.50.1