2

I am trying to build an iterator with python but i should use a true iterator for example using yields. I am only a beginner in python so I would appreciate every help.

class Graph(object):
        def __init__(self):
            #structure for edges and vertices
            self.__vertex_edge_map = {}

        def add_vertex(self,vertex):
            #add new vertex
            if vertex not in self.__vertex_edge_map:
                self.__vertex_edge_map[vertex] = []

        def add_edge(self,source,destination):
            #add edge 
            self.add_vertex(source)
            self.add_vertex(destination)
            if destination not in self.__vertex_edge_map[source]:
                self.__vertex_edge_map[source].append(destination)

!!!Edit: Therefore this program shows an directed graph. The Iterator should enumerate all edges of the graph. The order of iteration is up to you.

User546
  • 33
  • 4

0 Answers0