spiffyscore

tree.py at [c9abf46a9f]
Login

tree.py at [c9abf46a9f]

File tree.py artifact 29c78902c8 part of check-in c9abf46a9f


import pdb

class Tree():
    def __init__(self, name):
        self.nodes = []
        self.name = name

    def traverse_depth_first(self):
        all_nodes = []
        for node in self.nodes:
            if isinstance(node, Node):
                all_nodes.append(node)
            elif isinstance(node, Tree):
#                pdb.set_trace()
                all_nodes.extend(node.traverse_depth_first())
        return all_nodes

    def __str__(self):
        return str(self.__unicode__())
    def __unicode__(self):
        return self.nodes


class Node():
    def __init__(self, parent, data):
        self.parent = parent
        self.data = data

    def __str__(self):
        return str(self.__unicode__())
    def __unicode__(self):
        return self.data