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.
It says " You can use the element itself as an iterator to loop through all of its child elements."
You will see some people using len(node) along with recursion.
Others use node.iter() to retrieve all elements in the tree (node, children and subchildren) in one go.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
XML 1 - Find the Score
You are viewing a single comment's thread. Return to all comments →
This one-liner, below uses node.iter() and therefore does not need to use recursion:
Another way, below, uses a for loop (effectively the built-in function iter(node) and needs recursion:
To understand the above, read the ElementTree doc: https://diveintopython3.net/xml.html
It says " You can use the element itself as an iterator to loop through all of its child elements."
You will see some people using len(node) along with recursion. Others use node.iter() to retrieve all elements in the tree (node, children and subchildren) in one go.