Skip to content

Instantly share code, notes, and snippets.

@khornberg
Created October 21, 2021 20:54
Show Gist options
  • Save khornberg/a18e4d383d06edb4b1f86efcd9b761dc to your computer and use it in GitHub Desktop.
Save khornberg/a18e4d383d06edb4b1f86efcd9b761dc to your computer and use it in GitHub Desktop.
import graphlib
def ts_sort(topological_sorter):
topological_sorter.prepare()
spaces = 0
while topological_sorter:
nodes = topological_sorter.get_ready()
print(" "*spaces, nodes)
for node in nodes:
topological_sorter.done(node)
spaces += 2
ts = graphlib.TopologicalSorter()
ts.add('s1', 's0')
ts.add('s1', 's2')
ts_sort(ts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment