from typing import OrderedDict


def _groups_fail_table(groups):
    """Returns a dict associating each element to the groups it can fail.
    This function is used both in ``plot_elements_in_group`` and
    ``find_logical_saboteurs``.

    Parameters
    ----------
    groups
      Ordered dict of the form {group_name: [elements in groups]}.

    Returns
    -------
    fail_table
      A dict {element_name: list[True False False ...]} where list[i] is True
      if the element is part of the i-th group in the provided ordered
      dictionary ``groups``.
    """
    groups = list(groups.values())
    all_elements = []
    for group in groups:
        for element in group:
            if element not in all_elements:
                all_elements.append(element)
    return OrderedDict(
        [
            (element, [(element in group) for group in groups])
            for element in all_elements
        ]
    )