Learn Algorithm Design by Building a Shortest Path Algorithm - Step 26

Tell us what’s happening:

I have tried this so long. Can someone help me solve this?

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):
    for graph in shortest_path:
     unvisited = []
    unvisited.append()
     
        

# 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/128.0.0.0 Safari/537.36 Edg/128.0.0.0

Challenge Information:

Learn Algorithm Design by Building a Shortest Path Algorithm - Step 26

the code doesn’t pass

Hi @doanmaikhanhhung

What is the iterator, and what are you iterating through?

Happy coding

the iterator is the graph

why are you iteratirng over the function? wat should you be iterating over?

The function definition creates a new parameter/variable called graph. In the next line the for loop then defines a new variable called graph. That’s a problem.

Create a for loop to iterate over your graph

Each item in the graph is a node.

As mentioned, if you call your function currently, it will generate this error:

TypeError: 'function' object is not iterable

As a reminder this is the syntax of a ‘for’ loop:

for item in collection:
    code
    code

Be consistent with your indentation.