def rename_dict(d, ids=None):
    """Assigns new key names to a dictionary.

    Parameters
    ----------
    d : dict
        Dictionary to rename.
    ids : optional, array_like(shape=(len(d)))
        Desired key names. If none, the keys are numbered consecutively.

    Returns
    -------
    dict
        Dictionary with new names.

    Examples
    --------

    >>> d = {1: [0, 1], 2: None, 3: 'text'}
    >>> renamed_dict = rename_dict(d, ['first', 'second', 'last'])
    >>> print(sorted(renamed_dict))
    ['first', 'last', 'second']

    """
    if not isinstance(d, dict):
        raise TypeError('dictionary required')
    if ids is None:
        ids = range(len(d))
    elif not len(ids) == len(d):
        raise ValueError('same number of keys required')
    return dict(zip(ids, d.values()))
