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
commit38d2061cd14f8f8eb01e75e2f07404899aece25e (patch)
tree129b2edc0468bd6695b64c1aeb587474f518bd6e /Lib/heapq.py
parentb0084b9fb13e0152df62effe2a2ce8c5f1c7af6f (diff)
downloadcpython-38d2061cd14f8f8eb01e75e2f07404899aece25e.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