Open this example in the interactive library
Source code
from graphlib import CycleError, TopologicalSorter
try:
list(TopologicalSorter({'a': {'b'}, 'b': {'a'}}).static_order())
except CycleError:
print('Cycle detected')Sample output
Cycle detected
