Describe your issue in detail here.
I have tried replacing the my_graph in the for statement with unvisited and shortest_path but neither works. At this stage it’s telling me to apppend each node, but is that not what I did?
Your code so far
my_graph = {
'A': [('B', 3), ('D', 1)],
'B': [('A', 3), ('C', 4)],
'C': [('B', 4), ('D', 7)],
'D': [('A', 1), ('C', 7)]
}
/* User Editable Region */
def shortest_path(graph, start):
unvisited = []
for my_graph in graph:
unvisited.append('A', 'B', 'C', 'D')
/* User Editable Region */
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 OPR/105.0.0.0 (Edition std-1)
Challenge Information:
Learn Algorithm Design by Building a Shortest Path Algorithm - Step 21
Create a for loop to iterate over your graph, and append each node to the unvisited list.
You have a for loop iterating over the graph
for my_graph in graph:
A For loop defines a new variable here. You can’t use my_graph because that is already defined above, it’s taken.
append each node to the unvisited list.
Since your loop is looking at “each node” in the graph, you could call your new variable node.
for `<new variable>` in graph:
unvisited.append('A', 'B', 'C', 'D')
within the loop, each node is stored in the new variable, 1 at a time, for each loop. Imagine you didn’t know the contents of the graph, but you want to append the node to the list: You would append the variable which stores the node.
I appreciate this break down, and explanation for the for loop. I made the correction and used node as the new variable. I kept the append the same but I am still getting the error that they are not appended
that helped, thank you. I kept thinking I needed to put the values and not simply the variable. Going to keep those sites bookmarked so I can remind myself of that