<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def format_pkg_list(packages, versions_as_list, attr):
    '''
    Formats packages according to parameters for list_pkgs.
    '''
    ret = copy.deepcopy(packages)
    if attr:
        requested_attr = {'epoch', 'version', 'release', 'arch', 'install_date', 'install_date_time_t'}

        if attr != 'all':
            requested_attr &= set(attr + ['version'])

        for name in ret:
            versions = []
            for all_attr in ret[name]:
                filtered_attr = {}
                for key in requested_attr:
                    if all_attr[key]:
                        filtered_attr[key] = all_attr[key]
                versions.append(filtered_attr)
            ret[name] = versions
        return ret

    for name in ret:
        ret[name] = [format_version(d['epoch'], d['version'], d['release'])
                     for d in ret[name]]
    if not versions_as_list:
        stringify(ret)
    return ret