title: Creating a graph data structure in python using classes
body: <p>I am trying to create some type of class that will be generic enough to be used for both trees and graphs.</p>
  <pre><code>class Node:
      def __init__(self, value, children=[]):
          self.value = value
          self.children = children
  
      def add_child(self, child):
          self.children.append(child)
  
      def add_children(self, list_of_children):
          for child in list_of_children:
              self.add_child(child)
  
  def letterGraph():
      a = Node('A')
      b = Node('B')
      c = Node('C')
      d = Node('D')
      c = Node('C')
      e = Node('E')
      f = Node('F')
      g = Node('G')
  
      a.add_children([b, c])
      b.add_children([a, d, e])
      c.add_children([a, d])
      d.add_children([b, c, e, g, f])
      e.add_children([b, d, g])
      f.add_children([d, g])
      g.add_children([e, d, f])
  
      return a
  </code></pre>
  <p>It seems to work fine with trees, but with respect to graphs, when it adds a child to the current node, it will also add that same child to current node's children nodes.</p>
  <blockquote>
  <p>example:</p>
  <p>current_node: a</p>
  <p>a.add_children([b,c])</p>
  <p>current_node.children: [b,c]</p>
  <p>b.children: [b,c]`</p>
  </blockquote>