On step 45 from the learning Algorithm Design a Shortest Path Agorithm course

Dear Team, I am very lost with this step. Can you help me?? is there too many line in the if nested if Statement??

if paths[node] != [] and paths[node][-1] == node:
                   paths[node][-1] == node
                   paths[node] = paths[current]

And I am getting this error:
You should add paths[node] as the first condition to your nested if statement. Use the and operator to combine your conditions.

2 Likes

Hi @AbdulioUnited

There are a couple of issues with your code.

  1. Add an additional condition to your nested if statement to ensure that paths[node] is non-empty before accessing paths[node][-1].

The instructions ask you to modify only the if statement, so do not add to or modify the next lines of code.

  1. The syntax is not correct.

Happy coding

Thank you @Teller
All good with the issue n. 1.
For the issue number 2 (syntax issue) I am working on this sentence "ensure that paths[node] is non-empty. I removed the [node]

if paths != [] and paths[node][-1] == node:

what I am doing wrong?

Are you familiar with what makes a variable, or list, itself truthy or falsey?

can you please use descriptive titles for your posts? you have many that are just titles “freeCodeCamp.org” but that doesn’t say anything of the content of your post

2 Likes

I am getting there…I am in FreeCodeCamp to learn and I am sorry if I am bothering you. I am going back to study what I learned so far…Apparently I need more time.
Thanks…

You’re not bothering me, I get that you’re here to learn. This is the place to ask any questions you have, don’t worry!

Read about this here: https://www.freecodecamp.org/news/truthy-and-falsy-values-in-python/

And look at the examples:

a = 5

if a:
    print(a)
1 Like

Thank you …all good now but there is so much to do…

1 Like