Find attribute

Report a typo

You are given an XML document. Your program should read a string representing this document from input. The second line of input contains an attribute name that you should find in the root element. If the root contains this attribute, output its value. Otherwise, output None.

Sample Input 1:

<a attr="123"><b>hello</b><c/></a>
attr

Sample Output 1:

123

Sample Input 2:

<root a1="aba" a2="caba"/>
a3

Sample Output 2:

None
Write a program in Python 3
from lxml import etree
___

Create a free account to access the full topic