Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Node:
- def __init__(self, value):
- self._value = value
- self._children = []
- def __repr__(self):
- return f'Node({self._value})'
- def add_child(self, node):
- self._children.append(node)
- def __iter__(self):
- return iter(self._children)
- def depth_first(self):
- yield self
- for c in self:
- yield from c.depth_first()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement