In this HackerRank XML 1 - Find the Score problem solution You are given a valid XML document, and you have to print its score. The score is calculated by the sum of the score of each element. For any element, the score is equal to the number of attributes it has.

HackerRank XML 1 - Find the Score in python problem solution

HackerRank XML 1 - Find the Score in python problem solution

import xml.etree.ElementTree as etree
import sys

input()
tree = etree.ElementTree(etree.fromstring(sys.stdin.read()))
print(sum(len(el.attrib) for el in tree.getiterator()))