def METHOD_NAME(params, valid_keys, extra):
    """
    Merge valid keys from extra into params dictionary and return
    dictionary with keys which have been merged.
    Note: params is modified in place.
    """
    merged = {}
    if not extra:
        return merged
    for key in valid_keys:
        if key in extra:
            params[key] = extra[key]
            merged[key] = extra[key]
    return merged