Skip to content

Instantly share code, notes, and snippets.

@HotcockMiami
Created November 5, 2020 13:36
Show Gist options
  • Save HotcockMiami/d69a11e0b600b088030023d8ea172721 to your computer and use it in GitHub Desktop.
Save HotcockMiami/d69a11e0b600b088030023d8ea172721 to your computer and use it in GitHub Desktop.
import xmltodict
xml = """
<feed xml:lang='en'>
<title>NPBFX</title>
<subtitle lang='en'>Programming challenges
</subtitle>
<link rel='alternate' type='text/html' href='http://npbfx.com/' />
<updated>2020-10-28T12:00:00</updated>
</feed>
"""
xml_dict = xmltodict.parse(xml, xml_attribs = False)
print (xml_dict)
def depth(d):
if isinstance(d, dict):
return 1 + (max(map(depth, d.values())) if d else 0)
return 0
print (depth(xml_dict)-1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment