spiffyscore

tree.py at [4b32d1483b]
Login

tree.py at [4b32d1483b]

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


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