|
130 | 130 | 'nlargest', 'nsmallest', 'heappushpop'] |
131 | 131 |
|
132 | 132 | from itertools import islice, repeat, count, tee, chain |
133 | | -from operator import itemgetter, neg |
| 133 | +from operator import itemgetter |
134 | 134 | import bisect |
135 | 135 |
|
136 | 136 | def heappush(heap, item): |
@@ -413,13 +413,13 @@ def nlargest(n, iterable, key=None): |
413 | 413 |
|
414 | 414 | # When key is none, use simpler decoration |
415 | 415 | if key is None: |
416 | | - it = zip(iterable, map(neg, count())) # decorate |
| 416 | + it = zip(iterable, count(0,-1)) # decorate |
417 | 417 | result = _nlargest(n, it) |
418 | 418 | return list(map(itemgetter(0), result)) # undecorate |
419 | 419 |
|
420 | 420 | # General case, slowest method |
421 | 421 | 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 |
423 | 423 | result = _nlargest(n, it) |
424 | 424 | return list(map(itemgetter(2), result)) # undecorate |
425 | 425 |
|
|
0 commit comments