Kaydet (Commit) 8f2420c9 authored tarafından Raymond Hettinger's avatar Raymond Hettinger

Broaden the early-out test for nsmallest and nlargest

üst b0e69511
...@@ -197,7 +197,7 @@ def nlargest(n, iterable): ...@@ -197,7 +197,7 @@ def nlargest(n, iterable):
Equivalent to: sorted(iterable, reverse=True)[:n] Equivalent to: sorted(iterable, reverse=True)[:n]
""" """
if n < 0: if n <= 0:
return [] return []
it = iter(iterable) it = iter(iterable)
result = list(islice(it, n)) result = list(islice(it, n))
...@@ -215,7 +215,7 @@ def nsmallest(n, iterable): ...@@ -215,7 +215,7 @@ def nsmallest(n, iterable):
Equivalent to: sorted(iterable)[:n] Equivalent to: sorted(iterable)[:n]
""" """
if n < 0: if n <= 0:
return [] return []
it = iter(iterable) it = iter(iterable)
result = list(islice(it, n)) result = list(islice(it, n))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment