SHARE
TWEET

Untitled

a guest May 19th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top