You are viewing a single comment's thread. Return to all comments →
Each time the while begins, I expects all and only the nodes of a single level to be in this_level.
for _ in range(len(this_level)):
This line allows me to iterates only on the nodes in a single level, as their amount is the initial length.
If _ confuses you, it's just a convention symbol that states you don't need and won't use the corresponding variable, in this case the loop index.
node, score = this_level.pop(0)
The pop function removes the first element of the list. I remove the first since I am going to extend the list with the next level.
As the element I am going to pop is a tuple, I can assign both variable on a single line, thanks to Python sintax.
Feel free to keep asking! :)