|
130 | 130 | 'nlargest', 'nsmallest', 'heappushpop'] |
131 | 131 |
|
132 | 132 | from itertools import islice, repeat, count, tee, chain |
133 | | -from operator import itemgetter |
134 | 133 | import bisect |
135 | 134 |
|
136 | 135 | def heappush(heap, item): |
@@ -377,13 +376,13 @@ def nsmallest(n, iterable, key=None): |
377 | 376 | if key is None: |
378 | 377 | it = zip(iterable, count()) # decorate |
379 | 378 | result = _nsmallest(n, it) |
380 | | - return list(map(itemgetter(0), result)) # undecorate |
| 379 | + return [r[0] for r in result] # undecorate |
381 | 380 |
|
382 | 381 | # General case, slowest method |
383 | 382 | in1, in2 = tee(iterable) |
384 | 383 | it = zip(map(key, in1), count(), in2) # decorate |
385 | 384 | result = _nsmallest(n, it) |
386 | | - return list(map(itemgetter(2), result)) # undecorate |
| 385 | + return [r[2] for r in result] # undecorate |
387 | 386 |
|
388 | 387 | _nlargest = nlargest |
389 | 388 | def nlargest(n, iterable, key=None): |
@@ -415,13 +414,13 @@ def nlargest(n, iterable, key=None): |
415 | 414 | if key is None: |
416 | 415 | it = zip(iterable, count(0,-1)) # decorate |
417 | 416 | result = _nlargest(n, it) |
418 | | - return list(map(itemgetter(0), result)) # undecorate |
| 417 | + return [r[0] for r in result] # undecorate |
419 | 418 |
|
420 | 419 | # General case, slowest method |
421 | 420 | in1, in2 = tee(iterable) |
422 | 421 | it = zip(map(key, in1), count(0,-1), in2) # decorate |
423 | 422 | result = _nlargest(n, it) |
424 | | - return list(map(itemgetter(2), result)) # undecorate |
| 423 | + return [r[2] for r in result] # undecorate |
425 | 424 |
|
426 | 425 | if __name__ == "__main__": |
427 | 426 | # Simple sanity test |
|
0 commit comments