summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2009-02-21 08:58:42 (GMT)
committerRaymond Hettinger <python@rcn.com>2009-02-21 08:58:42 (GMT)
commitbe9b765c073eefcc109320b651d977ff03090f2f (patch)
tree228e112c70326c922a42e7c21e9dee7ec99f6004
parentaa681c7b99aa407d99d159924c4f2b295da3564b (diff)
downloadcpython-be9b765c073eefcc109320b651d977ff03090f2f.zip
cpython-be9b765c073eefcc109320b651d977ff03090f2f.tar.gz
cpython-be9b765c073eefcc109320b651d977ff03090f2f.tar.bz2
Speedup and simplify negative counter using count's new step argument.
-rw-r--r--Lib/heapq.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/Lib/heapq.py b/Lib/heapq.py
index 0c5a914..46dd4b6 100644
--- a/Lib/heapq.py
+++ b/Lib/heapq.py
@@ -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