13/32
Part 3 of 7 · CyclesLearn and do
Ask what to return, because a graph with a cycle has no full order
A cycle means no full order exists, so the function has to return something else. Python's own graphlib makes one choice.
from graphlib import CycleError, TopologicalSorter
graph = {task: [] for task in tasks}
for task, prerequisite in broken:
graph[task].append(prerequisite)
try:
list(TopologicalSorter(graph).static_order())
except CycleError as error:
print(error.args)
Python's own sorter raises CycleError on the broken pipeline. Which tasks does its message name?
Pick one to see what it prints.
Pick an answer above to see the rest