MCPcopy Create free account
hub / github.com/dabeaz/python-cookbook / Node

Class Node

src/4/delegating-iteration/example.py:3–15  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1# Example of delegating iteration to an internal container
2
3class Node:
4 def __init__(self, value):
5 self._value = value
6 self._children = []
7
8 def __repr__(self):
9 return 'Node({!r})'.format(self._value)
10
11 def add_child(self, node):
12 self._children.append(node)
13
14 def __iter__(self):
15 return iter(self._children)
16
17# Example
18if __name__ == '__main__':

Callers 1

example.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected