summaryrefslogtreecommitdiff
path: root/Lib/heapq.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2008-01-22 23:25:35 +0000
committerRaymond Hettinger <python@rcn.com>2008-01-22 23:25:35 +0000
commit1dfde1ddc0e1980d67bd19e187252d4e52b4f7ce (patch)
tree365fcd0e0d95e4ff612ca7184d441e6184f8b203 /Lib/heapq.py
parent86def6cb2b8d6d8c7f239795fa7af57c97a5890d (diff)
downloadcpython-git-1dfde1ddc0e1980d67bd19e187252d4e52b4f7ce.tar.gz
Replace map(None, *iterables) with zip(*iterables).
Diffstat (limited to 'Lib/heapq.py')
-rw-r--r--Lib/heapq.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/Lib/heapq.py b/Lib/heapq.py
index f3d0669934..48697f6393 100644
--- a/Lib/heapq.py
+++ b/Lib/heapq.py
@@ -351,7 +351,8 @@ def nsmallest(n, iterable, key=None):
Equivalent to: sorted(iterable, key=key)[:n]
"""
in1, in2 = tee(iterable)
- it = izip(map(key, in1), count(), in2) # decorate
+ keys = in1 if key is None else map(key, in1)
+ it = izip(keys, count(), in2) # decorate
result = _nsmallest(n, it)
return list(map(itemgetter(2), result)) # undecorate
@@ -362,7 +363,8 @@ def nlargest(n, iterable, key=None):
Equivalent to: sorted(iterable, key=key, reverse=True)[:n]
"""
in1, in2 = tee(iterable)
- it = izip(map(key, in1), map(neg, count()), in2) # decorate
+ keys = in1 if key is None else map(key, in1)
+ it = izip(keys, map(neg, count()), in2) # decorate
result = _nlargest(n, it)
return list(map(itemgetter(2), result)) # undecorate