MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / __bool__

Method __bool__

data_structures/heap/randomized_heap.py:202–216  ·  view source on GitHub ↗

Check if the heap is not empty. >>> rh = RandomizedHeap() >>> bool(rh) False >>> rh.insert(1) >>> bool(rh) True >>> rh.clear() >>> bool(rh) False

(self)

Source from the content-addressed store, hash-verified

200 return result
201
202 def __bool__(self) -> bool:
203 """
204 Check if the heap is not empty.
205
206 >>> rh = RandomizedHeap()
207 >>> bool(rh)
208 False
209 >>> rh.insert(1)
210 >>> bool(rh)
211 True
212 >>> rh.clear()
213 >>> bool(rh)
214 False
215 """
216 return self._root is not None
217
218
219if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected