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

    .. warning::

        If ``function`` returns a key-value pair with the same key
        more than once, it is undefined which value will be chosen
        for that key in the resulting dictionary.

    :param function: Function taking key and value as two arguments
                     and returning a new key-value pair, or None
                     (corresponding to identity function)

    .. versionadded:: 0.0.2
    """
    ensure_mapping(dict_)

    if function is None:
        function = lambda k, v: (k, v)
    else:
        ensure_callable(function)

    return dict_.__class__(starmap(function, iteritems(dict_)))