def perf_func(elem, func, level=0):
    func(elem, level)
for child in elem.getchildren():
    perf_func(child, func, level + 1)

def print_level(elem, level):
    print('-' * level + elem.tag)
root = ET.parse('XML_file.xml')
perf_func(root.getroot(), print_level)
Python - How to determine hierarchy level of parsed XML elements?