We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Each time the while begins, I expects all and only the nodes of a single level to be in this_level.
for_inrange(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! :)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Tree : Top View
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.
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.
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! :)