<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def filter_tree(tree):
 """Filter all 401 errors."""

    to_remove = []
    for elem in tree.findall('urldata'):
        valid = elem.find('valid')
        if valid is not None and valid.text == '0' and \
           valid.attrib.get('result', '').startswith('401'):
            to_remove.append(elem)
    root = tree.getroot()
    for elem in to_remove:
        root.remove(elem)