summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2009-02-21 22:10:18 (GMT)
committerRaymond Hettinger <python@rcn.com>2009-02-21 22:10:18 (GMT)
commitbd171bcfc416c71d2f5e3615f6a064dc2737e09b (patch)
tree3f19e51b9ebbbf8ae9a6ad3a4bf954b8ce719fdb
parent934896dc0977ea25dc37c13117525f2394625cee (diff)
downloadcpython-bd171bcfc416c71d2f5e3615f6a064dc2737e09b.zip
cpython-bd171bcfc416c71d2f5e3615f6a064dc2737e09b.tar.gz
cpython-bd171bcfc416c71d2f5e3615f6a064dc2737e09b.tar.bz2
Port r69838: 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 529fc2b..b361631 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, 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 = zip(iterable, map(neg, count())) # decorate
+ it = zip(iterable, count(0,-1)) # decorate
result = _nlargest(n, it)
return list(map(itemgetter(0), result)) # undecorate
# General case, slowest method
in1, in2 = tee(iterable)
- it = zip(map(key, in1), map(neg, count()), in2) # decorate
+ it = zip(map(key, in1), count(0,-1), in2) # decorate
result = _nlargest(n, it)
return list(map(itemgetter(2), result)) # undecorate