XML2 - Find the Maximum Depth

  • + 0 comments

    Working around the constraints of the call...

    maxdepth = 0
    
    def _depth(elem, level=0):
        if len(elem) == 0:
            return level
        return max(_depth(child, level + 1) for child in elem)
        
    def depth(elem, level=0):
        global maxdepth
        maxdepth = _depth(elem, 0)