import collections


def _merge_compiler_kwds(list_of_kwds):
    """
    Merges a list of keyword dictionaries. Values in these dictionaries are
    lists of values, the merged dictionaries will contain the concatenations
    of lists specified for the same key.

    Parameters
    ----------
    list_of_kwds : list of dict
        A list of compiler keyword dictionaries that should be merged.

    Returns
    -------
    merged_kwds : dict
        The merged dictionary
    """
    merged_kwds = collections.defaultdict(list)
    for kwds in list_of_kwds:
        for key, values in kwds.items():
            if not isinstance(values, list):
                raise TypeError(
                    "Compiler keyword argument '{}' requires a "
                    "list of values.".format(key)
                )
            merged_kwds[key].extend(values)
    return merged_kwds