mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Replace map(None, *iterables) with zip(*iterables).
This commit is contained in:
parent
86def6cb2b
commit
1dfde1ddc0
9 changed files with 20 additions and 90 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue