]> granicus.if.org Git - python/commitdiff
Speedup and simplify negative counter using count's new step argument.
authorRaymond Hettinger <python@rcn.com>
Sat, 21 Feb 2009 08:58:42 +0000 (08:58 +0000)
committerRaymond Hettinger <python@rcn.com>
Sat, 21 Feb 2009 08:58:42 +0000 (08:58 +0000)
Lib/heapq.py

index 0c5a914ae33940b7f7af6d1b075fbbff7ab0469b..46dd4b6efc67ccca9a3d214e89db42e77c71277c 100644 (file)
@@ -130,7 +130,7 @@ __all__ = ['heappush', 'heappop', 'heapify', 'heapreplace', 'merge',
            'nlargest', 'nsmallest', 'heappushpop']
 
 from itertools import islice, repeat, count, imap, izip, tee, chain
-from operator import itemgetter, neg
+from operator import itemgetter
 import bisect
 
 def heappush(heap, item):
@@ -413,13 +413,13 @@ def nlargest(n, iterable, key=None):
 
     # When key is none, use simpler decoration
     if key is None:
-        it = izip(iterable, imap(neg, count()))             # decorate
+        it = izip(iterable, count(0,-1))                    # decorate
         result = _nlargest(n, it)
         return map(itemgetter(0), result)                   # undecorate
 
     # General case, slowest method
     in1, in2 = tee(iterable)
-    it = izip(imap(key, in1), imap(neg, count()), in2)      # decorate
+    it = izip(imap(key, in1), count(0,-1), in2)             # decorate
     result = _nlargest(n, it)
     return map(itemgetter(2), result)                       # undecorate