<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def template_to_dict(tree, debug=0, find=False):
 """ returns wikitext template as dict debug = 1 prints minimal debug info to stdout debug > 1 compares _iter() versus _find() results find = True sets values from _find() algorithm (default _iter()) """


    # you can compare (most) raw Infobox wikitext like this:
    # https://en.wikipedia.org/wiki/TITLE?action=raw&section=0

    obj = defaultdict(str)
    errors = []
    for item in tree:
        try:
            name = item.findtext('name').strip()

            if debug:
                template_to_dict_debug(name, item, debug)

            find_val = template_to_dict_find(item, debug)  # DEPRECATED
            iter_val = template_to_dict_iter(item, debug)

            value = iter_val
            if find:
                value = find_val

            if name and value:
                obj[name] = value.strip()

        except AttributeError:

            if isinstance(item, lxml.etree.ElementBase):
                name = item.tag.strip()
                text = item.text.strip()
                if item.tag == 'title':
                    obj['infobox'] = text
                else:
                    obj[name] = text

        except:
            errors.append(lxml.etree.tostring(item))

    if errors:
        obj['errors'] = errors

    return dict(obj)