pygraphs.adjacency_list_to_graph#

adjacency_list_to_graph(adjacency, *, weight_key='weight', skip_validation=False)[source]#

Convert a graph represented as an adjacency list (AdjacencyList) to a graph represented as a dictionary (GraphRepresentation).

  • AdjacencyList: List[List[Integral]]]: A list of lists, where the outer list has a length equal to the number of vertices in the graph, and each inner list contains the neighbors (i.e., [v1, v2, ...]) of the corresponding vertex (from outer vertex to inner vertex). For a weighted graph, the form List[List[Tuple[Integral, Real]]] is used where the inner lists contain tuples of the form \((v, w)\), where \(v\) is a neighbor vertex and \(w\) is the weight of the edge connecting the vertex to its neighbor. To store more than weight, the form List[List[Tuple[Integral, Dict[str, Any]]]] is used.

  • GraphRepresentation: Dict[int, Dict[int, Dict[str, Any]]]: A dictionary where the keys are vertex identifiers and the values are dictionaries mapping neighboring vertex identifiers to edge attributes (e.g., weight). This is the internal representation used by the pygraphs.Graph class.

Parameters:
  • adjacency (AdjacencyList) – The adjacency list to convert into graph representation.

  • weight_key (str, optional (default: 'weight')) – The key to use for storing edge weights in the graph representation when the adjacency list is weighted.

Returns:

graph – The graph represented as a dictionary.

Return type:

GraphRepresentation