0

[Solved] Can someone explain why the outputs are different here ?

Check this code, https://code.sololearn.com/cXs6wY2auuLV/?ref=app For the first loop i assign new values to row and col using a,b = val1, val2 For the second loop I use a = val1 b = val2 For some unknown reasons the outputs are different and from what the output is I see that it skips some iterations in between. I really don't understand why this is happening. Any answer is appreciated, thanks :)

6th Sep 2019, 2:27 PM
RZK 022
RZK 022 - avatar
11 ответов
+ 3
I'm just waiting for some python expert to notice this
6th Sep 2019, 3:38 PM
RZK 022
RZK 022 - avatar
+ 3
In the first example, the values of "row" and "col" are the same for "data[row][col][0]" and "data[row][col][1]". This is because "row,col = ..." reassigns them simultaneosly. In the second example, the value of "row" in "data[row][col][1]" is different than the one used in "data[row][col][0]" because you're reassigning "row" in line 23. Therefore, in line 24 you use the new value, not the old one.
6th Sep 2019, 6:00 PM
Diego
Diego - avatar
+ 3
Diego oh .... How could I have not seen that, thanks.
7th Sep 2019, 12:51 AM
RZK 022
RZK 022 - avatar
+ 2
~ swim ~ (not available on messanger) the algorithm works fine on both now, but now I'm left with the above problem, why does that even happen when both are the same thing.
6th Sep 2019, 3:31 PM
RZK 022
RZK 022 - avatar
+ 2
~ swim ~ (not available on messanger) the list in the program above is generated by that algorithm, in the function I named tracePath() all the time I thought the bug was in the search function but then I realized that it was the while loop in the output function which was going wrong.
6th Sep 2019, 3:33 PM
RZK 022
RZK 022 - avatar
+ 1
This problem arissed when I was implementing A* algorithm, I made the c++ version then tried on python, and it took me more than 6 hours to figure out the bug was in the last loop.
6th Sep 2019, 3:27 PM
RZK 022
RZK 022 - avatar