User Tools

Site Tools


stacks_queues

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
stacks_queues [2020/01/14 02:14] – [heapqueue] jrsetistacks_queues [2020/01/14 02:16] (current) jrseti
Line 4: Line 4:
 ====heapqueue==== ====heapqueue====
  
-  heapq.**__heappush__**(heap, item)+https://docs.python.org/2/library/heapq.html 
 + 
 +  heapq.heappush(heap, item)
   Push the value item onto the heap, maintaining the heap invariant.   Push the value item onto the heap, maintaining the heap invariant.
      
-  heapq.**__heappop__**(heap)+  heapq.heappop(heap)
   Pop and return the smallest item from the heap, maintaining the heap invariant. If the heap is empty, IndexError    Pop and return the smallest item from the heap, maintaining the heap invariant. If the heap is empty, IndexError 
   is raised. To access the smallest item without popping it, use heap[0].   is raised. To access the smallest item without popping it, use heap[0].
      
-  heapq.**__heappushpop__**(heap, item)+  heapq.heappushpop(heap, item)
   Push item on the heap, then pop and return the smallest item from the heap. The    Push item on the heap, then pop and return the smallest item from the heap. The 
   combined action runs more efficiently than heappush() followed by a separate call    combined action runs more efficiently than heappush() followed by a separate call 
   to heappop().   to heappop().
      
-  heapq.__heapify__(x)+  heapq.heapify(x)
   Transform list x into a heap, in-place, in linear time.   Transform list x into a heap, in-place, in linear time.
      
-  heapq.**__heapreplace__**(heap, item)+  heapq.heapreplace(heap, item)
   Pop and return the smallest item from the heap, and also push the new item. The    Pop and return the smallest item from the heap, and also push the new item. The 
   heap size doesn’t change. If the heap is empty, IndexError is raised.   heap size doesn’t change. If the heap is empty, IndexError is raised.
Line 34: Line 36:
   The module also offers three general purpose functions based on heaps.   The module also offers three general purpose functions based on heaps.
      
-  heapq.**__merge__**(*iterables)+  heapq.merge(*iterables)
   Merge multiple sorted inputs into a single sorted output (for example, merge    Merge multiple sorted inputs into a single sorted output (for example, merge 
   timestamped entries from multiple log files). Returns an iterator over the sorted values.   timestamped entries from multiple log files). Returns an iterator over the sorted values.
Line 42: Line 44:
   sorted (smallest to largest).   sorted (smallest to largest).
      
-  heapq.**__nlargest__**(n, iterable[, key])+  heapq.nlargest(n, iterable[, key])
   Return a list with the n largest elements from the dataset defined by iterable. key,    Return a list with the n largest elements from the dataset defined by iterable. key, 
   if provided, specifies a function of one argument that is used to extract a comparison    if provided, specifies a function of one argument that is used to extract a comparison 
Line 48: Line 50:
     sorted(iterable, key=key, reverse=True)[:n]     sorted(iterable, key=key, reverse=True)[:n]
      
-  heapq.**__nsmallest__**(n, iterable[, key])+  heapq.nsmallest(n, iterable[, key])
   Return a list with the n smallest elements from the dataset defined by iterable. key,    Return a list with the n smallest elements from the dataset defined by iterable. key, 
   if provided, specifies a function of one argument that is used to extract a comparison    if provided, specifies a function of one argument that is used to extract a comparison 
   key from each element in the iterable: key=str.lower    key from each element in the iterable: key=str.lower 
     Equivalent to: sorted(iterable, key=key)[:n]     Equivalent to: sorted(iterable, key=key)[:n]
stacks_queues.1578968085.txt.gz · Last modified: 2020/01/14 02:14 by jrseti