Advertisement
Guest User

Untitled

a guest
May 19th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. class Node:
  2. def __init__(self, value):
  3. self._value = value
  4. self._children = []
  5.  
  6. def __repr__(self):
  7. return f'Node({self._value})'
  8.  
  9. def add_child(self, node):
  10. self._children.append(node)
  11.  
  12. def __iter__(self):
  13. return iter(self._children)
  14.  
  15. def depth_first(self):
  16. yield self
  17. for c in self:
  18. yield from c.depth_first()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement