Return a new dictionary where the keys come from applying ``function``
    to the keys of given dictionary.

    .. warning::

        If ``function`` returns the same value for more than one key,
        it is undefined which key will be chosen for the resulting dictionary.

    :param function: Function taking a dictionary key,
                     or None (corresponding to identity function)

    .. versionadded:: 0.0.2

def mapkeys(function, dict_):
    """Return a new dictionary where the keys come from applying ``function``
    to the keys of given dictionary.

    .. warning::

        If ``function`` returns the same value for more than one key,
        it is undefined which key will be chosen for the resulting dictionary.

    :param function: Function taking a dictionary key,
                     or None (corresponding to identity function)

    .. versionadded:: 0.0.2
    """
    ensure_mapping(dict_)
    function = identity() if function is None else ensure_callable(function)
    return dict_.__class__((function(k), v) for k, v in iteritems(dict_))