]> granicus.if.org Git - python/commitdiff
Broaden the early-out test for nsmallest and nlargest
authorRaymond Hettinger <python@rcn.com>
Wed, 26 Mar 2014 09:00:54 +0000 (02:00 -0700)
committerRaymond Hettinger <python@rcn.com>
Wed, 26 Mar 2014 09:00:54 +0000 (02:00 -0700)
Lib/heapq.py

index d615239b94608a89ffd570724953347d7e0cd675..d52cd715e12d9fbeec70553e0e45c9f878c31503 100644 (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))