for block in blocks:
    group = document.find('./group[@name="{}"]'.format(block))
if group:
    xml.etree.ElementTree.dump(group)
else:
    print('Group {} not found.'.format(group))
Python - Elementtree - Search through tree using a variable