Complete the code to represent a weighted edge between two nodes.
edge = ([1], 5)
The first element in the tuple represents the node name, so "A" is correct.
Complete the code to add a weighted edge from node 'A' to node 'B' with weight 7 in an adjacency list.
graph["A"] = [("B", [1])]
The weight of the edge from 'A' to 'B' is 7, so 7 is the correct value.
Fix the error in the weighted graph representation by completing the missing weight value.
edges = {"A-B": [1]The weight should be a number, so 3 is correct. Using a string or None is incorrect.
Fill both blanks to create a dictionary comprehension that maps nodes to their weighted edges with weights greater than 4.
{node: edges for node, edges in graph.items() if edges[0][[1]] [2] 4}The weight is at index 1 in the edge tuple, and we want weights greater than 4, so use 1 and >.
Fill all three blanks to create a dictionary comprehension that maps each node to the weight of its first edge if the weight is less than 10.
{node: edges[[1]][[2]] for node, edges in graph.items() if edges[0][[3]] < 10}The first blank selects the first edge (index 0), the second blank selects the weight (index 1), and the third blank checks the weight (index 1) for the condition.