I am writing a very simple Tree class:
class Tree:
def __init__(self, value_ = None, children_ = None):
self.value = value_
self.children = children_
I would like to be able to bypass DFS and BFS using a simple loop, that is:
t = Tree()
for node in t:
print(node.value)
In C ++, for example, you can have several types of iterators - so I could define both a DFS and a BFS iterator and use this or that option depending on what type of workaround I wanted to do. Is this possible to do in Python?
source
share