]> granicus.if.org Git - python/commitdiff
Fix argument order in pure python version of nsmallest() and nlargest().
authorRaymond Hettinger <python@rcn.com>
Mon, 29 Nov 2004 05:54:48 +0000 (05:54 +0000)
committerRaymond Hettinger <python@rcn.com>
Mon, 29 Nov 2004 05:54:48 +0000 (05:54 +0000)
Lib/heapq.py
Lib/test/test_heapq.py

index 14a00dc04b863e30a392dfcabc4099ed21117e38..b4ebb91f1485b73c227c696f2e8f8c14bef25763 100644 (file)
@@ -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]
index 7848e4e98a06cb0a8ec3317606dd0e85b1bf8fee..68003e7f981042d95261bb217ae9187134e5f4aa 100644 (file)
@@ -39,8 +39,11 @@ class TestHeap(unittest.TestCase):
         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.