MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / __iter__

Method __iter__

data_structures/heap/skew_heap.py:141–157  ·  view source on GitHub ↗

Returns sorted list containing all the values in the heap. >>> sh = SkewHeap([3, 1, 3, 7]) >>> list(sh) [1, 3, 3, 7]

(self)

Source from the content-addressed store, hash-verified

139 return self._root is not None
140
141 def __iter__(self) -> Iterator[T]:
142 """
143 Returns sorted list containing all the values in the heap.
144
145 >>> sh = SkewHeap([3, 1, 3, 7])
146 >>> list(sh)
147 [1, 3, 3, 7]
148 """
149 result: list[Any] = []
150 while self:
151 result.append(self.pop())
152
153 # Pushing items back to the heap not to clear it.
154 for item in result:
155 self.insert(item)
156
157 return iter(result)
158
159 def insert(self, value: T) -> None:
160 """

Callers

nothing calls this directly

Calls 3

popMethod · 0.95
insertMethod · 0.95
appendMethod · 0.45

Tested by

no test coverage detected