mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
Fix argument order in pure python version of nsmallest() and nlargest().
This commit is contained in:
parent
f4c7c402d4
commit
e1defa4175
2 changed files with 7 additions and 4 deletions
|
|
@ -175,7 +175,7 @@ def heapify(x):
|
|||
for i in reversed(xrange(n//2)):
|
||||
_siftup(x, i)
|
||||
|
||||
def nlargest(iterable, n):
|
||||
def nlargest(n, iterable):
|
||||
"""Find the n largest elements in a dataset.
|
||||
|
||||
Equivalent to: sorted(iterable, reverse=True)[:n]
|
||||
|
|
@ -195,7 +195,7 @@ def nlargest(iterable, n):
|
|||
result.sort(reverse=True)
|
||||
return result
|
||||
|
||||
def nsmallest(iterable, n):
|
||||
def nsmallest(n, iterable):
|
||||
"""Find the n smallest elements in a dataset.
|
||||
|
||||
Equivalent to: sorted(iterable)[:n]
|
||||
|
|
|
|||
|
|
@ -39,8 +39,11 @@ def test_push_pop(self):
|
|||
self.check_invariant(results)
|
||||
|
||||
self.assertRaises(TypeError, heappush, [])
|
||||
self.assertRaises(TypeError, heappush, None, None)
|
||||
self.assertRaises(TypeError, heappop, None)
|
||||
try:
|
||||
self.assertRaises(TypeError, heappush, None, None)
|
||||
self.assertRaises(TypeError, heappop, None)
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
def check_invariant(self, heap):
|
||||
# Check the heap invariant.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue