code: def write_hypergraph(hgr, colored = False):
       
      dotG = pydot.Dot()
      
      if not 'name' in dir(hgr):
          dotG.set_name('hypergraph')
      else:
          dotG.set_name(hgr.name)
      
      colortable = {}
      colorcount = 0
      
      # Add all of the nodes first
      for node in hgr.nodes():
          newNode = pydot.Node(str(node), hyper_node_type = 'hypernode')
          
          dotG.add_node(newNode)
      
      for hyperedge in hgr.hyperedges():
          
          if (colored):
              colortable[hyperedge] = colors[colorcount % len(colors)]
              colorcount += 1
              
              newNode = pydot.Node(str(hyperedge), hyper_node_type = 'hyperedge', \
                                                   color = str(colortable[hyperedge]), \
                                                   shape = 'point')
          else:
              newNode = pydot.Node(str(hyperedge), hyper_node_type = 'hyperedge')
          
          dotG.add_node(newNode)
          
          for link in hgr.links(hyperedge):
              newEdge = pydot.Edge(str(hyperedge), str(link))
              dotG.add_edge(newEdge)
      
      return dotG.to_string()
docs: Return a string specifying the given hypergraph in DOT Language.
      
      @type  hgr: hypergraph
      @param hgr: Hypergraph.
      
      @type  colored: boolean
      @param colored: Whether hyperedges should be colored.
  
      @rtype:  string
      @return: String specifying the hypergraph in DOT Language.