from typing import Dict
from typing import List
from typing import Tuple


def _is_explanation_equal(dict1: Dict[str, List[Tuple[str, float]]],
                          dict2: Dict[str, List[Tuple[str, float]]]) -> bool:
    """
    Tests if the two dictionaries of a given structure are equal.

    The both of the input parameters must be a dictionary with string keys and
    list values. The latter is composed of 2-tuples of strings and floats.

    The keys in the dictionary and the tuples must match exactly, while the
    floats only need to be approximately equal. The ordering of the tuples in
    the list does not need to be the same.

    Parameters
    ----------
    dict1 : Dictionary[string, List[Tuple[string, float]]]
        The first dictionary to be compared.
    dict2 : Dictionary[string, List[Tuple[string, float]]]
        The second dictionary to be compared.

    Returns
    -------
    equal : boolean
        ``True`` if the dictionaries are the same, ``False`` otherwise.
    """
    if set(dict1.keys()) == set(dict2.keys()):
        equal = True
        for key in dict1:
            val1 = sorted(dict1[key])
            val2 = sorted(dict2[key])

            if len(val1) != len(val2):
                equal = False
                break

            for i in range(len(val1)):
                if val1[i][0] != val2[i][0]:
                    equal = False
                    break
                if abs(val1[i][1] - val2[i][1]) > 1e-1:
                    equal = False
                    break

            if not equal:
                break
    else:
        equal = False
    return equal