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

Method __iter__

data_structures/binary_tree/is_sum_tree.py:19–32  ·  view source on GitHub ↗

>>> root = Node(2) >>> list(root) [2] >>> root.left = Node(1) >>> tuple(root) (1, 2)

(self)

Source from the content-addressed store, hash-verified

17 right: Node | None = None
18
19 def __iter__(self) -> Iterator[int]:
20 """
21 >>> root = Node(2)
22 >>> list(root)
23 [2]
24 >>> root.left = Node(1)
25 >>> tuple(root)
26 (1, 2)
27 """
28 if self.left:
29 yield from self.left
30 yield self.data
31 if self.right:
32 yield from self.right
33
34 def __len__(self) -> int:
35 """

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected