def compare_dict(answer, result, decimal=7):
    flat_answer = bc.utils.flatten(answer)
    flat_result = bc.utils.flatten(result)

    for key in flat_answer.keys():
        if key not in flat_result.keys():
            return False, "The key {} was not there.".format(key)

        answer_v, result_v = flat_answer[key], flat_result[key]

        if isinstance(answer_v, (float, int)) and isinstance(result_v, (float, int)):
            try:
                np.testing.assert_almost_equal(answer_v, result_v, decimal=decimal)
            except AssertionError:
                err_msg = "The key {} produced a different result: expected {}, got {}.".format(key, answer_v, result_v)
                return False, err_msg
        elif answer_v != result_v:
            return False, "The key {} produced a different result: expected {}, got {}.".format(key, answer_v, result_v)

    return True, ""
Returns true if two dictionaries are approximately equal. Returns false otherwise.
dataset/ETHPy150Open yvesalexandre/bandicoot/bandicoot/tests/testing_tools.py/compare_dict