This repository has been archived on 2015-04-29. You can view files and clone it, but cannot push or open issues or pull requests.
psh/tree.py
2015-02-26 16:30:48 -05:00

22 lines
582 B
Python

class TreeNode(object):
"""A tree node holds some data and has iterable children."""
def __init__(self, data):
"""Initializes a data. The data can be any type, but it usually
is an ordered dictionary."""
self.parent = None
self.data = data
self.children = []
def add_child(self, child):
"""Adds a child to the node."""
child.parent = self
self.children.apppend(child)
def children(self):
"""Returns an iterable generator for all the children nodes."""
def children_generator():
for child in self.children:
yield child
return children_generator()