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

Tell us what’s happening:

I have tried the steps based on forum can someone guide me how can i pass for loop and get this code pass.

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 node in my_graph:
        unvisited.append(node)

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

Challenge Information:

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

Can you try to talk about how you got stuck debugging please?

i was going through as per the steps and even after writting the code not sure why its not taking my input can you please look into it and let me know how can i proceed.

If you are not willing to try to say more, you are really not going to progress in your learning very much.

can you tell us how you came to write what you wrote? what was your thinking process?

i was just going through the above statement and through this i thought of trying it and also i have checked the forum if anyoe have attended this before or not and thought of giving a try but the code is not going through.

This doesn’t say anything about what is inside of your brain. It is pretty obvious that you tried this code and read the forum. But can you say what thoughts were inside of your brain? Why did you write the code you did (and not “I thought it was right”)?

It would help a lot if you could describe what each line of code does, starting with this one

sorry for the delay but if you want me to explain in simple words as the steps suggested to create a for loop and add an append to univsited i did the same but its not taking my code so can someone from your end can help me in solving this problem.

Sure, can you explain what you think each line you added, one by one, does?

You’ve explained the instructions, which isn’t necessary.

If you explain each line of code that you’ve written, one line at a time, then we can understand what it is we need to explain. You may even discover the solution yourself in this exercise.

first i have created function def shorted_path(graph, start):

that’s great, what about the other lines?

second i have written a for loop starts with for node in my_graph
unvisited.append(node) but it is still not taking it can you please help me in this.

Can you explain this line a bit more please? What does each part of this statement mean? “def” means to define a function, right? What about the other parts?

for means creating a for loop for the function where the output will get stop if i put a range in it lets say range(5) so in this the output will get executed 5 times consecutively including 0 as their first number as python reads from 0

And what about this def line? What is shorted_path? What is graph? What is start?

dude i have created a function by name shorted_path with parameters as graph and start hope this is making sense and can we please focus on solving the problem instead of asking what each step is defining

We are trying to solve the problem. The problem is that you are asking for the solution without putting time into debugging. We are guiding you through the debugging.

We absolutely will not just give you the answer. Please work with us on the debugging so we can help you find the bug.

i understand your point in helping me understand the concept but i do know a little bit about python i have done it till dictionaries the only problem i am getting is even after putting the code its not accepting my code so for that i believe the answer would be the right solution instead of question what i was doing or telling me to narrate each line of code it just doesnt make much sense to me but if you feel that i can learn from this then please by all means go ahead.