XML 1 - Find the Score

Sort by

recency

|

200 Discussions

|

  • + 0 comments
    import sys
    import xml.etree.ElementTree as etree
    def get_attr_number(node):
        return sum(len(x.attrib) for x in node.iter())
    if __name__ == '__main__':
        sys.stdin.readline()
        xml = sys.stdin.read()
        tree = etree.ElementTree(etree.fromstring(xml))
        root = tree.getroot()
        print(get_attr_number(root))
    
  • + 0 comments

    return sum(len(a.attrib) for a in node.iter())

  • + 0 comments
    def get_attr_number(node):
        attrs = len(node.attrib)
        if len(node) == 0:
            return attrs
        return attrs + sum(get_attr_number(child) for child in node)
    
  • + 0 comments
    def get_attr_number(node):
        total = 0
        for child in node.iter():
            total += int(len(child.attrib))
        return total
        
    
  • + 0 comments
    import sys
    import xml.etree.ElementTree as etree
    def get_attr_number(node):
        total = 0
        for elem in node.iter():
            score = len(elem.attrib)
            total += score
        return total
    if __name__ == '__main__':
        sys.stdin.readline()
        xml = sys.stdin.read()
        tree = etree.ElementTree(etree.fromstring(xml))
        root = tree.getroot()
        print(get_attr_number(root))