PyDocs

Nav

Data Types

TopologicalSorter

graphlib

class · Added in 3.9 (source)
  • TopologicalSorter(graph=None)
Provides functionality to topologically sort a graph of hashable nodes
Members of TopologicalSorter

a

add
Add a new node and its predecessors to the graph.

d

done
Marks a set of nodes returned by "get_ready" as processed.

g

get_ready
Return a tuple of all the nodes that are ready.

i

is_active
Return ``True`` if more progress can be made and ``False`` otherwise.

p

prepare
Mark the graph as finished and check for cycles in the graph.

s

static_order
Returns an iterable of nodes in a topological order.
1 Example
>>> graph = {"D": {"B", "C"}, "C": {"A"}, "B": {"A"}}
>>> ts = TopologicalSorter(graph)
>>> tuple(ts.static_order())
('A', 'C', 'B', 'D')
from the Python docs
See Also
No see-alsos for graphlib/TopologicalSorter
0 Notes
No notes for TopologicalSorter