human
I wrote the below code

    if isinstance(search_filts, dict):
        search_filts = [search_filts]
    def _get_id(resource):
        if (resource_type == 'instance'):
            return resource.get('uuid')
    def _match_any(pattern_list, string):
        if isinstance(pattern_list, str):
            pattern_list = [pattern_list]
        return any([re.match(pattern, string) for pattern in pattern_list])
    def _filter_metadata(resource, search_filt, input_metadata):
        ids = search_filt.get('resource_id', [])
        keys_filter = search_filt.get('key', [])
        values_filter = search_filt.get('value', [])
        output_metadata = {}
        if (ids and (_get_id(resource) not in ids)):
            return {}
        for (k, v) in input_metadata.items():
            if (keys_filter and values_filter and (not _match_any(keys_filter, k)) and (not _match_any(values_filter, v))):
                continue
            elif ((keys_filter and (not _match_any(keys_filter, k))) or (values_filter and (not _match_any(values_filter, v)))):
                continue
            output_metadata[k] = v
        return output_metadata
    formatted_metadata_list = []
    for res in resource_list:
        if (resource_type == 'instance'):
            if (metadata_type is None):
                metadata_type = 'metadata'
            metadata = res.get(metadata_type, {})
        for filt in search_filts:
            metadata = _filter_metadata(res, filt, metadata)
        for (k, v) in metadata.items():
            formatted_metadata_list.append({'key': k, 'value': v, ('%s_id' % resource_type): _get_id(res)})
    return formatted_metadata_list

What's a good function header?
 Here's a good function header?
assistant
#Here's a good function header.

def filter_and_format_resource_metadata(resource_type, resource_list, search_filts, metadata_type=None):