Created
March 27, 2017 00:31
-
-
Save metric-space/e110fb820f6b5a00c2611006dba232bd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Node: | |
| def __init__(self,val,parent=None): | |
| self.val = val | |
| self.children = [] | |
| self.parent = parent | |
| def __eq__(self,other): | |
| if self.val == other.val: | |
| return True | |
| return False | |
| def addChildNode(self,node): | |
| for i in self.children: | |
| if i == node: | |
| return i | |
| node.parent = self.val | |
| self.children.append(node) | |
| return node | |
| def addChildNodeListOfVals(self, list_of_nodes): | |
| if list_of_nodes == []: | |
| return | |
| head = list_of_nodes[0] | |
| tail = list_of_nodes[1:] | |
| aa = Node(head) | |
| egg = self.addChildNode(aa) | |
| egg.addChildNodeListOfVals(tail) | |
| def printez(self): | |
| gatherChildren = [] | |
| for i in self.children: | |
| gatherChildren.append(i.printez()) | |
| return {"name":self.val, | |
| "parent":self.parent, | |
| "children":gatherChildren} | |
| a = ["reddit"] | |
| b = ["reddit","chicken","beta","side.pp"] | |
| c = ["reddit","chicken","eta","snake.pp"] | |
| egg = Node("website") | |
| egg.addChildNodeListOfVals(a) | |
| egg.addChildNodeListOfVals(b) | |
| egg.addChildNodeListOfVals(c) | |
| print(egg.printez()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment