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.PyDAG.neighbors#
- PyDAG.neighbors(node, /)#
Return a list of node indices of neighbors (i.e. successors) in a directed graph
A successor is defined as a node that has a directed edge pointing from the specified node. In a multigraph, where two nodes can be connected by multiple edges, each successor node index is returned only once.
This function is equivalent to
successor_indices()
.>>> G = rx.PyDiGraph() >>> G.add_nodes_from(["A", "B", "C", "D", "E"]) NodeIndices[0, 1, 2, 3, 4] >>> G.extend_from_edge_list([(0, 1), (1, 2), (1, 3), (1, 4)]) >>> G.neighbors(1) # neighbors of the 'B' node NodeIndices[4, 3, 2]
To get the data of these nodes, see
successors()
.To filter the successors by the attributes of the connecting edge, see
find_successors_by_edge()
.See also
predecessor_indices()
.For undirected graphs, see
neighbors()
.- Parameters:
node (int) – The index of the node to get the neighbors of
- Returns:
A list of the neighboring node indices
- Return type: