Python nodes

i just learned about nodes in codecademy and how one can use nodes to store data and link to another node.But is it possible to link to two nodes from a single node.
i tried to do it but it didn’t work.
im posting my code below.

class Node: def __init__(self, value, link_node=None): self.value = value self.link_node = link_node def set_link_node(self, link_node): self.link_node = link_node def get_link_node(self): return self.link_node def get_value(self): return self.value # Add your code below: yacko = Node('likes to yak') wacko = Node('has a penchant for hoarding snacks') dot = Node('enjoys spending time in movie lots') yacko.set_link_node(wacko) yacko.set_link_node(dot) dot.set_link_node(wacko) dots_data = yacko.get_link_node().get_value() wackos_data = dot.get_link_node().get_value() print(dots_data) print(wackos_data)

I guess you could do that by storing a list of nodes instead of a single node,
but then you’d have to change the functions to be able to handle lists.

Here’s an example:

class Node: def __init__(self, value, link_node=None): self.value = value self.link_node = link_node def set_link_node(self, link_node, add=False): if add == True and type(self.link_node) == list: if link_node not in self.link_node: self.link_node.append(link_node) else: self.link_node = link_node def get_link_node(self, index=None): if index is None: return self.link_node elif type(self.link_node) == list: return self.link_node[index] def get_value(self): return self.value yacko = Node('likes to yak', []) wacko = Node('has a penchant for hoarding snacks') dot = Node('enjoys spending time in movie lots') yacko.set_link_node(wacko, True) yacko.set_link_node(dot, True) dot.set_link_node(wacko) dots_data = yacko.get_link_node(1).get_value() wackos_data = yacko.get_link_node(0).get_value() print(dots_data) print(wackos_data) print('Animaniacs')

I think having nodes that link to multiple nodes is a tree.