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

Method __len__

data_structures/binary_tree/is_sum_tree.py:34–43  ·  view source on GitHub ↗

>>> root = Node(2) >>> len(root) 1 >>> root.left = Node(1) >>> len(root) 2

(self)

Source from the content-addressed store, hash-verified

32 yield from self.right
33
34 def __len__(self) -> int:
35 """
36 >>> root = Node(2)
37 >>> len(root)
38 1
39 >>> root.left = Node(1)
40 >>> len(root)
41 2
42 """
43 return sum(1 for _ in self)
44
45 @property
46 def is_sum_node(self) -> bool:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected