]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport 69858: In Py3.x, a list comprehension is now faster than list(map(itemgette...
authorRaymond Hettinger <python@rcn.com>
Sat, 21 Feb 2009 23:27:02 +0000 (23:27 +0000)
committerRaymond Hettinger <python@rcn.com>
Sat, 21 Feb 2009 23:27:02 +0000 (23:27 +0000)
Lib/heapq.py

index 55a3027eb6e27f4c68ccb2532905bb8da057feca..638ecd17a29910c1214cf4604e1dd1facf561da3 100644 (file)
@@ -130,7 +130,7 @@ __all__ = ['heappush', 'heappop', 'heapify', 'heapreplace', 'merge',
            'nlargest', 'nsmallest', 'heappushpop']
 
 from itertools import islice, repeat, count, tee
-from operator import itemgetter, neg
+from operator import neg
 import bisect
 
 def heappush(heap, item):
@@ -357,11 +357,11 @@ def nsmallest(n, iterable, key=None):
     if key is None:
         it = zip(iterable, count())                         # decorate
         result = _nsmallest(n, it)
-        return list(map(itemgetter(0), result))             # undecorate
+        return [r[0] for r in result]                       # undecorate
     in1, in2 = tee(iterable)
     it = zip(map(key, in1), count(), in2)                   # decorate
     result = _nsmallest(n, it)
-    return list(map(itemgetter(2), result))                 # undecorate
+    return [r[2] for r in result]                           # undecorate
 
 _nlargest = nlargest
 def nlargest(n, iterable, key=None):
@@ -372,11 +372,11 @@ def nlargest(n, iterable, key=None):
     if key is None:
         it = zip(iterable, map(neg, count()))               # decorate
         result = _nlargest(n, it)
-        return list(map(itemgetter(0), result))             # undecorate
+        return [r[0] for r in result]                       # undecorate
     in1, in2 = tee(iterable)
     it = zip(map(key, in1), map(neg, count()), in2)         # decorate
     result = _nlargest(n, it)
-    return list(map(itemgetter(2), result))                 # undecorate
+    return [r[2] for r in result]                           # undecorate
 
 if __name__ == "__main__":
     # Simple sanity test