def param_combinations(key_values):
    """Recursively combine the value lists that appear in a keyword values dict
    into dictionaries describing combinations of simple values.

    More directly, it reduces a dict describing valid keyword values to
    CRDS bestrefs header dicts:

    { valid keyword values dict... } -->
        [ bestrefs_header1, bestrefs_header2, ...]

    or in more detail:

    { keyword1 : [values_for_keyword1, ...], ...}  -->
        [{ keyword1 : simple_value_for_keyword1, ...}, ...]
    """
    if isinstance(key_values, dict):
        key_values = list(key_values.items())
    if key_values:
        combs = []
        key, values = key_values[0]
        for subcomb in param_combinations(key_values[1:]):
            if len(values):
                for value in values:
                    comb = dict(subcomb)
                    comb[key] = value
                    combs.append(comb)
            else:
                combs.append(subcomb)
        return combs
    else:
        return [{}]