mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Merge 3.1
This commit is contained in:
commit
37e6c54ba1
7 changed files with 55 additions and 34 deletions
|
@ -170,7 +170,7 @@ def heappushpop(heap, item):
|
|||
return item
|
||||
|
||||
def heapify(x):
|
||||
"""Transform list into a heap, in-place, in O(len(heap)) time."""
|
||||
"""Transform list into a heap, in-place, in O(len(x)) time."""
|
||||
n = len(x)
|
||||
# Transform bottom-up. The largest index there's any point to looking at
|
||||
# is the largest with a child index in-range, so must have 2*i + 1 < n,
|
||||
|
@ -360,7 +360,7 @@ def nsmallest(n, iterable, key=None):
|
|||
return [min(chain(head, it))]
|
||||
return [min(chain(head, it), key=key)]
|
||||
|
||||
# When n>=size, it's faster to use sort()
|
||||
# When n>=size, it's faster to use sorted()
|
||||
try:
|
||||
size = len(iterable)
|
||||
except (TypeError, AttributeError):
|
||||
|
@ -398,7 +398,7 @@ def nlargest(n, iterable, key=None):
|
|||
return [max(chain(head, it))]
|
||||
return [max(chain(head, it), key=key)]
|
||||
|
||||
# When n>=size, it's faster to use sort()
|
||||
# When n>=size, it's faster to use sorted()
|
||||
try:
|
||||
size = len(iterable)
|
||||
except (TypeError, AttributeError):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue