import re


def _flatten_params(params):
    """
    Turns a list of parameters with values into a flat tuple list of lists
    so we can permute
    :param params:
    :return:
    """
    flat_params = []
    for i, (opt_name, opt_arg) in enumerate(params.items()):
        if opt_arg.tunable:
            clean_name = opt_name.strip('-')
            clean_name = re.sub('-', '_', clean_name)
            param_groups = []
            for val in opt_arg.opt_values:
                param_groups.append({'idx': i, 'val': val, 'name': clean_name})
            flat_params.append(param_groups)
    return flat_params