def _replace_keys(kwargs, replacements):
    """Replace illegal keys in kwargs with another value."""

    for key, replacement in replacements.items():
        if key in kwargs:
            kwargs[replacement] = kwargs[key]
            del kwargs[key]
    return kwargs