def transform_list_to_dict(thelist, thedefaults, key_to_index_map):
    """
    Transform thelist into a dict with keys according to key_map and defaults
    from thedefaults.
    """
    return {
        key: thelist[key_to_index_map[key]]
        if key_to_index_map[key] is not None else thedefaults[key]
        for key in key_to_index_map
    }