Kaydet (Commit) 4800d647 authored tarafından Éric Araujo's avatar Éric Araujo

Minor tweaks to a few comments in heapq

üst e4f8d839
...@@ -178,7 +178,7 @@ def heappushpop(heap, item): ...@@ -178,7 +178,7 @@ def heappushpop(heap, item):
return item return item
def heapify(x): 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) n = len(x)
# Transform bottom-up. The largest index there's any point to looking at # 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, # is the largest with a child index in-range, so must have 2*i + 1 < n,
...@@ -368,7 +368,7 @@ def nsmallest(n, iterable, key=None): ...@@ -368,7 +368,7 @@ def nsmallest(n, iterable, key=None):
return [min(chain(head, it))] return [min(chain(head, it))]
return [min(chain(head, it), key=key)] 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: try:
size = len(iterable) size = len(iterable)
except (TypeError, AttributeError): except (TypeError, AttributeError):
...@@ -406,7 +406,7 @@ def nlargest(n, iterable, key=None): ...@@ -406,7 +406,7 @@ def nlargest(n, iterable, key=None):
return [max(chain(head, it))] return [max(chain(head, it))]
return [max(chain(head, it), key=key)] 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: try:
size = len(iterable) size = len(iterable)
except (TypeError, AttributeError): except (TypeError, AttributeError):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment