This is the documentation for the current state of the development branch of rustworkx. The documentation or APIs here can change prior to being released.


lexicographical_topological_sort(dag, key, /)#

Get the lexicographical topological sorted nodes from the provided DAG

This function returns a list of nodes data in a graph lexicographically topologically sorted using the provided key function. A topological sort is a linear ordering of vertices such that for every directed edge from node \(u\) to node \(v\), \(u\) comes before \(v\) in the ordering.

This function differs from topological_sort() because when there are ties between nodes in the sort order this function will use the string returned by the key argument to determine the output order used.

  • dag (PyDiGraph) – The DAG to get the topological sorted nodes from

  • key (callable) – key is a python function or other callable that gets passed a single argument the node data from the graph and is expected to return a string which will be used for resolving ties in the sorting order.


A list of node’s data lexicographically topologically sorted.

Return type: