Note

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.

rustworkx.PyDiGraph.find_predecessors_by_edge#

PyDiGraph.find_predecessors_by_edge(node, filter_fn, /)#

Return a list of data associated with the predecessors of the given node, where the edges connecting from those nodes satisfy the provided filter function.

A predecessor is defined as a node that has a directed edge pointing to the specified node. This method returns all nodes where the edges match the condition.

>>> G = rx.PyDiGraph()
>>> G.add_nodes_from(["A", "B", "C", "D", "E"])
NodeIndices[0, 1, 2, 3, 4]
>>> G.extend_from_weighted_edge_list([(0, 3, 10), (1, 3, 20), (2, 3, 30), (3, 4, 10)])
>>> G.find_predecessors_by_edge(3, lambda x: x < 25)
['B', 'A']

To get one node only, see find_predecessor_node_by_edge().

Parameters:
  • node (int) – The index of the node to get the predecessors for

  • filter_fn (Callable) – The filter function to apply on edges. It takes in one argument, the edge data payload/weight object, and returns a boolean whether the edge matches the conditions or not. If any edge returns True, the node will be included.

Returns:

A list of the node data for all the predecessor nodes where at least one edge leading from it matches the filter

Return type:

list[S]