'Graphlib Topological sorting not showing vertex that is not completed
topological_sorter.get_ready() does not seem to show the same vertex twice even if it was not yet marked as done using topological_sorter.done(node)
from graphlib import TopologicalSorter
graph = {"D": {"B", "C"}, "C": {"A"}, "B": {"A"}, "E": {}}
topological_sorter = TopologicalSorter(graph)
topological_sorter.prepare()
def return_active():
if topological_sorter.is_active():
active_list = []
for node in topological_sorter.get_ready():
active_list.append(node)
return active_list
a = return_active()
print(a)
topological_sorter.done("A")
b = return_active()
print(b)
Output:
a = ['A', 'E']
b = ['C', 'B']
I was expecting b = ['E', 'C', 'B'] instead of ['C', 'B'] only
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
