File tree Expand file tree Collapse file tree 1 file changed +18
-9
lines changed
Expand file tree Collapse file tree 1 file changed +18
-9
lines changed Original file line number Diff line number Diff line change 44Domain : Python
55Author : Ahmedur Rahman Shovon
66Created : 15 July 2016
7+ Updated : 08 February 2023
78Problem : https://www.hackerrank.com/challenges/xml-1-find-the-score/problem
89"""
910
10- # Enter your code here. Read input from STDIN. Print output to STDOUT
11- xml_str = ""
12- n = int (input ())
13- for _ in range (n ):
14- tmp_str = input ()
15- xml_str = xml_str + tmp_str
11+ import sys
12+ import xml .etree .ElementTree as etree
1613
17- cnt = xml_str .count ("='" )
18- xml_str = ""
19- print (cnt )
14+ def get_attr_number (node ):
15+ total = len (node .attrib .keys ())
16+ for child in node :
17+ if child :
18+ total += get_attr_number (child )
19+ else :
20+ total += len (child .attrib .keys ())
21+ return total
22+
23+ if __name__ == '__main__' :
24+ sys .stdin .readline ()
25+ xml = sys .stdin .read ()
26+ tree = etree .ElementTree (etree .fromstring (xml ))
27+ root = tree .getroot ()
28+ print (get_attr_number (root ))
You can’t perform that action at this time.
0 commit comments