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.
- Prepare
- Python
- XML
- XML 1 - Find the Score
- Discussions
XML 1 - Find the Score
XML 1 - Find the Score
Sort by
recency
|
195 Discussions
|
Please Login in order to post a comment
jeanpierrefouche solution is very good, I like for loops more than recursion.
def get_attr_number(node): n = 0 if len(node.attrib) !=0: n+= len(node.attrib) for child in node: n +=get_attr_number(child) return n
def get_attr_number(node): import xml.etree.ElementTree as etree tree = etree.ElementTree(etree.fromstring(xml))