Replace map(None, *iterables) with zip(*iterables).
diff --git a/Lib/heapq.py b/Lib/heapq.py
index f3d0669..48697f6 100644
--- a/Lib/heapq.py
+++ b/Lib/heapq.py
@@ -351,7 +351,8 @@
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 @@
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