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:10] 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
-Push the value item onto the heap, maintaining the heap invariant.+
  
-heapq.**heappop**(heap) +  heapq.heappush(heap, item) 
-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]. +  Push the value item onto the heap, maintaining the heap invariant. 
- +   
-**heapq.heappushpop**(heap, item) +  heapq.heappop(heap) 
-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 to heappop(). +  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]. 
-New in version 2.6. +   
- +  heapq.heappushpop(heap, item) 
-heapq.heapify(x) +  Push item on the heap, then pop and return the smallest item from the heap. The  
-Transform list x into a heap, in-place, in linear time. +  combined action runs more efficiently than heappush() followed by a separate call  
- +  to heappop(). 
-heapq.**heapreplace**(heap, item) +   
-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. +  heapq.heapify(x) 
- +  Transform list x into a heap, in-place, in linear time. 
-This one step operation is more efficient than a heappop() followed by heappush() and can be more appropriate when using a fixed-size heap. The pop/push combination always returns an element from the heap and replaces it with item. +   
- +  heapq.heapreplace(heap, item) 
-The value returned may be larger than the item added. If that isn’t desired, consider using heappushpop() instead. Its push/pop combination returns the smaller of the two values, leaving the larger value on the heap. +  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. 
-The module also offers three general purpose functions based on heaps. +   
- +  This one step operation is more efficient than a heappop() followed by heappush()  
-heapq.**merge**(*iterables) +  and can be more appropriate when using a fixed-size heap. The pop/push combination  
-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. +  always returns an element from the heap and replaces it  
- +  with item. 
-Similar to sorted(itertools.chain(*iterables)) but returns an iterable, does not pull the data into memory all at once, and assumes that each of the input streams is already sorted (smallest to largest). +   
- +  The value returned may be larger than the item added. If that isn’t desired,  
-New in version 2.6. +  consider using heappushpop() instead. Its push/pop combination returns the smaller  
- +  of the two values, leaving the larger value on the heap. 
-heapq.**nlargest**(n, 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 key from each element in the iterable: key=str.lower Equivalent to: sorted(iterable, key=key, reverse=True)[:n] +  The module also offers three general purpose functions based on heaps. 
- +   
-heapq.**nsmallest**(n, iterable[, key]) +  heapq.merge(*iterables) 
-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 key from each element in the iterable: key=str.lower Equivalent to: sorted(iterable, key=key)[:n]+  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. 
 +   
 +  Similar to sorted(itertools.chain(*iterables)) but returns an iterable, does not pull  
 +  the data into memory all at once, and assumes that each of the input streams is already  
 +  sorted (smallest to largest). 
 +   
 +  heapq.nlargest(n, 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  
 +  key from each element in the iterable: key=str.lower Equivalent to:  
 +    sorted(iterable, key=key, reverse=True)[:n] 
 +   
 +  heapq.nsmallest(n, 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  
 +  key from each element in the iterable: key=str.lower  
 +    Equivalent to: sorted(iterable, key=key)[:n]
stacks_queues.1578967827.txt.gz · Last modified: 2020/01/14 02:10 by jrseti