Find the password

Report a typo

Imagine you are a hacker. You've got a file containing information about a user of Hyperskill. It is an XML document that contains their personal information as well as their email and password. But the document is very large and you can't find the password in it manually. You see that all information about the user is stored in attributes, and you are sure that the password is being stored in the password attribute. So you decided to use Python to find the password.

You should implement a function find_password(xml_string). The content of the XML document will be passed to this function as a string. Your code shouldn't read anything from input. Traverse the XML document using the lxml library and find the password and return it.

Tip: If the initial problem seems too difficult for you, you can solve an easier version of it. Try to find the password among the attributes of one of the root's children (like in the first sample). If the password can not be found there, you can return None. So, in the second sample, None is also a valid answer.

Sample Input 1:

<profile><account login="login" password="secret"/></profile>

Sample Output 1:

secret

Sample Input 2:

<result>
  <webpage link="hyperskill.com"></webpage>
  <users>
    <!-- Random comment -->
    <user id="239" password="qwerty"><info email="[email protected]"/></user>
  </users>
</result>

Sample Output 2:

qwerty
Write a program in Python 3
from lxml import etree

def find_password(xml_string):
pass
___

Create a free account to access the full topic