old_contents: #!/usr/local/bin/python
  # edX Intro to Computational Thinking and Data Science
  # Graphs lecture code
  
  
  class Node(object):
      """docstring for Node"""
  
      def __init__(self, name):
          """ Assumes name is a string"""
          self.name = name
  
      def getName(self):
          return self.name
  
      def __str__(self):
          return self.name
  
  
  class Edge(object):
      """docstring for Edge"""
  
      def __init__(self, src, dest):
          """Assumes src and dest are nodes"""
          self.src = src
          self.dest = dest
  
      def getSource(self):
          return self.src
  
      def getDestination(self):
          return self.dest
  
      def __str__(self):
          return self.src.getName() + '->' + self.dest.getName()
  
new_contents: #!/usr/local/bin/python
  # edX Intro to Computational Thinking and Data Science
  # Graphs lecture code
  
  
  class Node(object):
      """docstring for Node"""
  
      def __init__(self, name):
          """Assumes name is a string"""
          self.name = name
  
      def getName(self):
          return self.name
  
      def __str__(self):
          return self.name
  
  
  class Edge(object):
      """docstring for Edge"""
  
      def __init__(self, src, dest):
          """Assumes src and dest are nodes"""
          self.src = src
          self.dest = dest
  
      def getSource(self):
          return self.src
  
      def getDestination(self):
          return self.dest
  
      def __str__(self):
          return self.src.getName() + '->' + self.dest.getName()
  
  
  class Digraph(object):
      """docstring for Digraph"""
  
      def __init__(self):
          self.edges = {}
  
      def addNode(self, node):
          if node in self.edges:
              raise ValueError('Duplicate node')
          else:
              self.edges[node] = []
  
      def addEdge(self, edge):
          src = edge.getSource()
          dest = edge.getDestination()
          if not (src in self.edges and dest in self.edges):
              raise ValueError('Node not in graph')
          self.edges[src].append(dest)
  
      def childrenOf(self, node):
          return self.edges[node]
  
      def hasNode(self, node):
          return node in self.edges
  
      def getNode(self, name):
          for n in self.edges:
              if n.getName() == name:
                  return n
          raise NameError(name)
  
      def __str__(self):
          result = ''
          for src in self.edges:
              for dest in self.edges[src]:
                  result = result + src.getName() + '->' + dest.getName() + '\n'
          return result[:-1]  # omit final newline
  
subject: Add Digraph class to graphs code