import six


def get_async_result_tuples(results):
    """
    Given a dictionary like::

        {
            arg_0: {
                0: result or exception obj
                1: result or exception obj 
                2: result or exception obj 
            },
            arg_1: {
                0: result or exception obj
                1: result or exception obj 
                2: result or exception obj 
            },
        }

    Return a list, composed of tuples of (host, arg, result)
    where arg is the input argument, host is the host index and
    result is the response/result object from the zookeeper api call

    Any results that contain exception objects / errors are ignored.

    :param result: A result set dictionary as returned from ``get_async_call_per_host``
    :returns: ``list``
    """
    if not isinstance(results, dict):
        raise ValueError('"result" must be dict, got: %s' % type(dict))

    items = []

    for arg, host_result in six.viewitems(results):
        items.extend([(host, arg, result) for host, result in six.viewitems(host_result) if not isinstance(result, Exception)])

    return items