from pathlib import Path


def map_list_to_kwargs(file_names: list, mapping: dict):
    """
    Maps a list of files to their corresponding *mrconvert* inputs kwargs.

    Parameters
    ----------
    file_names : list
        A list of existing files.

    Returns
    -------
    Tuple[str, str, str, str]
        Four sorted outputs: *in_file*,*json*,*bvec*,*bval*
    """

    out_dict = {}
    for file_name in file_names:
        suffixes = Path(file_name).suffixes
        suffix = "".join(suffixes).lstrip(".")
        for key, val in mapping.items():
            if suffix in val:
                out_dict[key] = file_name
    return out_dict