import itertools


def construct_pipelines(config):
    """ Uses the (parsed) configuration dict to generate a preprocessing pipeline.

    Args:
        config <dict>: parsed contents of a configuration file.

    Returns:
        pipelines <list>: a list of nippy preprocessing pipelines.
    """


    def _get_argument_combinations(arguments):
        """ Utility to function to obtain all permutations of preprocessing arguments. """
        arg_names = sorted(arguments)
        combinations = itertools.product(*(arguments[arg] for arg in arg_names))
        combinations = [dict(zip(arg_names, arg_values)) for arg_values in combinations]
        return combinations

    options = {}
    for key in config.keys():
        # 1. Check if we got also_skip
        if 'also_skip' in config[key] and config[key]['also_skip']:
            config[key].pop('also_skip')
            options[key] = _get_argument_combinations(config[key])
            options[key].append(None)
        else:
            options[key] = _get_argument_combinations(config[key])

    return _get_argument_combinations(options)