Minor clean-ups.
This commit is contained in:
parent
68b272b477
commit
450ed10c5e
|
@ -397,7 +397,7 @@ def merge(*iterables, key=None, reverse=False):
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
_heappop(h)
|
_heappop(h)
|
||||||
if h:
|
if h:
|
||||||
key_value, order, value, next = h[0]
|
key_value, order, value, next = h[0]
|
||||||
yield value
|
yield value
|
||||||
yield from next.__self__
|
yield from next.__self__
|
||||||
|
|
||||||
|
@ -413,7 +413,7 @@ def merge(*iterables, key=None, reverse=False):
|
||||||
# number of comparisons
|
# number of comparisons
|
||||||
# n inputs k-extreme values (average of 5 trials) % more than min()
|
# n inputs k-extreme values (average of 5 trials) % more than min()
|
||||||
# ------------- ---------------- --------------------- -----------------
|
# ------------- ---------------- --------------------- -----------------
|
||||||
# 1,000 100 3,317 133.2%
|
# 1,000 100 3,317 233.2%
|
||||||
# 10,000 100 14,046 40.5%
|
# 10,000 100 14,046 40.5%
|
||||||
# 100,000 100 105,749 5.7%
|
# 100,000 100 105,749 5.7%
|
||||||
# 1,000,000 100 1,007,751 0.8%
|
# 1,000,000 100 1,007,751 0.8%
|
||||||
|
@ -496,6 +496,8 @@ def nsmallest(n, iterable, key=None):
|
||||||
# When key is none, use simpler decoration
|
# When key is none, use simpler decoration
|
||||||
if key is None:
|
if key is None:
|
||||||
it = iter(iterable)
|
it = iter(iterable)
|
||||||
|
# put the range(n) first so that zip() doesn't
|
||||||
|
# consume one too many elements from the iterator
|
||||||
result = [(elem, i) for i, elem in zip(range(n), it)]
|
result = [(elem, i) for i, elem in zip(range(n), it)]
|
||||||
if not result:
|
if not result:
|
||||||
return result
|
return result
|
||||||
|
@ -594,4 +596,4 @@ def nlargest(n, iterable, key=None):
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
import doctest
|
import doctest
|
||||||
doctest.testmod()
|
print(doctest.testmod())
|
||||||
|
|
Loading…
Reference in New Issue