From 1dfde1ddc0e1980d67bd19e187252d4e52b4f7ce Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Tue, 22 Jan 2008 23:25:35 +0000 Subject: Replace map(None, *iterables) with zip(*iterables). --- Lib/heapq.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Lib/heapq.py') 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 -- cgit v1.2.1