[Python-checkins] r69859 - python/branches/release30-maint/Lib/heapq.py
raymond.hettinger
python-checkins at python.org
Sun Feb 22 00:27:02 CET 2009
Author: raymond.hettinger
Date: Sun Feb 22 00:27:02 2009
New Revision: 69859
Log:
Backport 69858: In Py3.x, a list comprehension is now faster than list(map(itemgetter(0), iterable)).
Modified:
python/branches/release30-maint/Lib/heapq.py
Modified: python/branches/release30-maint/Lib/heapq.py
==============================================================================
--- python/branches/release30-maint/Lib/heapq.py (original)
+++ python/branches/release30-maint/Lib/heapq.py Sun Feb 22 00:27:02 2009
@@ -130,7 +130,7 @@
'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 @@
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 @@
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
More information about the Python-checkins
mailing list