<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def list_template(root, topics, templates, inventory, be, absolute=False):
 """List contents for resolved template Resolve a template as far as possible via the given `topics`. For example, if a template supports 5 arguments, but only 3 are given, resolve the template until its 4th argument and list the contents thereafter. In some cases, an additional path is present following an argument, e.g. {3}/assets. The `/assets` portion is referred to as the "tail" and is appended also. Arguments: topics (tuple):
 Current topics templates (dict):
 templates.yaml inventory (dict):
 inventory.yaml be (dict):
 be.yaml """


    project = topics[0]

    # Get item
    try:
        key = be.get("templates", {}).get("key") or "{1}"
        item = item_from_topics(key, topics)
        binding = binding_from_item(inventory, item)

    except KeyError:
        return []

    except IndexError as exc:
        raise IndexError("At least %s topics are required" % str(exc))

    fields = replacement_fields_from_context(
        context(root, project))
    binding = binding_from_item(inventory, item)
    pattern = pattern_from_template(templates, binding)

    # 2 arguments, {1}/{2}/{3} -> {1}/{2}
    # 2 arguments, {1}/{2}/assets/{3} -> {1}/{2}/assets
    index_end = pattern.index(str(len(topics)-1)) + 2
    trimmed_pattern = pattern[:index_end]

    # If there aren't any more positional arguments, we're done
    print trimmed_pattern
    if not re.findall("{[\d]+}", pattern[index_end:]):
        return []

    # Append trail
    # e.g. {1}/{2}/assets
    #             ^^^^^^^
    try:
        index_trail = pattern[index_end:].index("{")
        trail = pattern[index_end:index_end + index_trail - 1]
        trimmed_pattern += trail
    except ValueError:
        pass

    try:
        path = trimmed_pattern.format(*topics, **fields)
    except IndexError:
        raise IndexError("Template for \"%s\" has unordered "
                         "positional arguments: \"%s\"" % (item, pattern))

    if not os.path.isdir(path):
        return []

    items = list()
    for dirname in os.listdir(path):
        abspath = os.path.join(path, dirname).replace("\\", "/")
        if not os.path.isdir(abspath):
            continue

        if absolute:
            items.append(abspath)
        else:
            items.append(dirname)

    return items