That is because you are only removing attributes, not the elements themselves
Try:
dict = {}
for parent in tree.iter():
for child in parent:
if 'key' in child.attrib:
if child.attrib['key'] == 'phc.filename':
dict[child] = parent
elif child.attrib['key'] == 'phc.line_number':
dict[child] = parent
for child in dict:
parent = dict[child]
parent.remove(child)