Question: python language pls, here are some test cases. graph_string = D 3 0 1 1 0 0 2 print(adjacency_list(graph_string)). graph_string = D

python language pls, here are some test cases.
graph_string = """\ D 3 0 1 1 0 0 2 """ print(adjacency_list(graph_string)).
graph_string = """\ D 3 W 0 1 7 1 0 -2 0 2 0 """ print(adjacency_list(graph_string))
from pprint import pprint # undirected graph in the textbook example graph_string = """\ U 7 1 2 1 5 1 6 2 3 2 5 3 4 4 5 """ pprint(adjacency_list(graph_string))
Write a function adjacency_list(graph_str) that takes the textual representation of a graph (as a string) and returns its adjacency list. The returned adjacency list must be a list of lists. The length of the outer list is equal to the number of vertices. The inner lists have one element for each edge. The elements are two-tuples where the first element of the tuple is the vertex the edge goes to, and the second element of the tuple is the weight. For unweighted graphs the second element of the tuple is None. The inner lists must be populated as the edge information is read from the graph string. This order is important. Note that for undirected graphs, each edge is stored two times (in opposite directions)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
