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.adj#
- PyDAG.adj(node, /)#
Get the index and data for the neighbors of a node.
This will return a dictionary where the keys are the node indices of the adjacent nodes (inbound or outbound) and the value is the edge data objects between that adjacent node and the provided node. Note in the case of a multigraph only one edge will be used, not all of the edges between two node.
>>> 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, 2, "A->C"), (1, 2, "B->C"), (2, 3, "C->D"), (3, 4, "D->E")]) >>> G.adj(2) # neighbors of the node "C" {1: 'B->C', 0: 'A->C', 3: 'C->D'}
For direction-aware neighbors, see
adj_direction()
.- Parameters:
node (int) – The index of the node to get the neighbors of
- Returns:
A dictionary where the keys are the node indices and the values are the edge data objects for all nodes that share an edge with the specified node.
- Return type:
dict[int, T]