Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd171bc

Browse files
committed
Port r69838: Speedup and simplify negative counter using count's new step argument.
1 parent 934896d commit bd171bc

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

Lib/heapq.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
'nlargest', 'nsmallest', 'heappushpop']
131131

132132
from itertools import islice, repeat, count, tee, chain
133-
from operator import itemgetter, neg
133+
from operator import itemgetter
134134
import bisect
135135

136136
def heappush(heap, item):
@@ -413,13 +413,13 @@ def nlargest(n, iterable, key=None):
413413

414414
# When key is none, use simpler decoration
415415
if key is None:
416-
it = zip(iterable, map(neg, count())) # decorate
416+
it = zip(iterable, count(0,-1)) # decorate
417417
result = _nlargest(n, it)
418418
return list(map(itemgetter(0), result)) # undecorate
419419

420420
# General case, slowest method
421421
in1, in2 = tee(iterable)
422-
it = zip(map(key, in1), map(neg, count()), in2) # decorate
422+
it = zip(map(key, in1), count(0,-1), in2) # decorate
423423
result = _nlargest(n, it)
424424
return list(map(itemgetter(2), result)) # undecorate
425425

0 commit comments

Comments
 (0)