Skip to content Skip to sidebar Skip to footer

Dfs On A Graph Using A Python Generator

I am using a generator to do a full search on a graph, the real data set is fairly large, here is a portion of the code i wrote on a small data set: class dfs: def __init__(

Solution 1:

Perhaps I'm misunderstanding your question, but it seems to me that you want to replace your __iter__ function with something like this:

def __iter__(self):
    for start inself.start_nodes:
        forendinself.end_nodes:
            forpathinself.find_path(self._graph, start, end):
                yieldpath

You can find more information about generators in this question.

Post a Comment for "Dfs On A Graph Using A Python Generator"