spiffyscore

tree.py at [18dba95a2e]
Login

tree.py at [18dba95a2e]

File tree.py artifact 7aba067c30 part of check-in 18dba95a2e


import pdb

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

    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