import sysimport xml.etree.ElementTree as etreedefget_attr_number(node): count =len(node.attrib)for each in node:iflen(each)>1:for i in each: count +=len(i.attrib)else: count +=len(each.attrib)return countif__name__=='__main__': sys.stdin.readline() xml = sys.stdin.read() tree = etree.ElementTree(etree.fromstring(xml)) root = tree.getroot()print(get_attr_number(root))
XML 2 - Find the Maximum Depth
import xml.etree.ElementTree as etreemaxdepth =0defdepth(elem,level):global maxdepth level +=1if level > maxdepth: maxdepth = levelfor each in elem:depth(each, level)if__name__=='__main__': n =int(input()) xml =""for i inrange(n): xml = xml +input()+"\n" tree = etree.ElementTree(etree.fromstring(xml))depth(tree.getroot(), -1)print(maxdepth)