def remove_key(d, key):
    """Safely remove the `key` from the dictionary.

    Safely remove the `key` from the dictionary `d` by first
    making a copy of dictionary. Return the new dictionary together
    with the value stored for the `key`.

    Parameters
    ----------
    d : dict
        The dictionary from which to remove the `key`.
    key :
        The key to remove

    Returns
    -------
    v :
        The value for the key
    r : dict
        The dictionary with the key removed.

    """
    r = dict(d)
    v = r[key]
    del r[key]
    return v, r