2018/08.py
def infer_one_to_one_from_possibles(possibles: Dict[K, Set[V]]):
    """
    This goes through a dictionary of key to potential values and computes the true
    value using simple inference where if a key can only be a single value, then it must
    be that value. For example:

        A -> {X, Y}
        B -> {Y}
        C -> {X, Z}

    then B -> Y, which means that A cannot be Y, thus A must be X, and by the same logic
    C must be Z.
    """
    inferred = {}
    while len(possibles):
        # Find the alergen that only has one ingredient associated with it and pull it
        # out of the possibles dictionary, and remove the ingredient from all of the
        # other sets.
        for idx, possible_fields in possibles.items():
            if len(possible_fields) == 1:
                inferred[idx] = possible_fields.pop()
                remove_idx = idx
                break
        else:  # nobreak
            assert False, "No keys have a single possible value"

        del possibles[remove_idx]
        for x in possibles:
            if inferred[remove_idx] in possibles[x]:
                possibles[x].remove(inferred[remove_idx])

    return inferred

    This goes through a dictionary of key to potential values and computes the true
    value using simple inference where if a key can only be a single value, then it must
    be that value. For example:

        A -> {X, Y}
        B -> {Y}
        C -> {X, Z}

    then B -> Y, which means that A cannot be Y, thus A must be X, and by the same logic
    C must be Z.
    
This goes through a dictionary of key to potential values and computes the true
value using simple inference where if a key can only be a single value, then it must
be that value. For example.



then B -> Y, which means that A cannot be Y, thus A must be X, and by the same logic
C must be Z.
This goes through a dictionary of key to potential values and computes the true value using simple inference where if a key can only be a single value then it must be that value . For example . then B - > Y which means that A cannot be Y thus A must be X and by the same logic C must be Z .
def infer_one_to_one_from_possibles(possibles: Dict[K, Set[V]]):
    inferred = {}
    while len(possibles):
        for idx, possible_fields in possibles.items():
            if len(possible_fields) == 1:
                inferred[idx] = possible_fields.pop()
                remove_idx = idx
                break
        else:  
            assert False, "No keys have a single possible value"
        del possibles[remove_idx]
        for x in possibles:
            if inferred[remove_idx] in possibles[x]:
                possibles[x].remove(inferred[remove_idx])
    return inferred
def infer_one_to_one_from_possibles ( possibles : Dict [ K , Set [ V ] ] ) : inferred = { } while len ( possibles ) : for idx , possible_fields in possibles . items ( ) : if len ( possible_fields ) == 1 : inferred [ idx ] = possible_fields . pop ( ) remove_idx = idx break else : assert False , "No keys have a single possible value" del possibles [ remove_idx ] for x in possibles : if inferred [ remove_idx ] in possibles [ x ] : possibles [ x ] . remove ( inferred [ remove_idx ] ) return inferred
This goes through a dictionary of key to potential values and computes the true
value using simple inference where if a key can only be a single value, then it must
be that value.
This goes through a dictionary of key to potential values and computes the true value using simple inference where if a key can only be a single value then it must be that value .
"""
    This goes through a dictionary of key to potential values and computes the true
    value using simple inference where if a key can only be a single value, then it must
    be that value. For example:

        A -> {X, Y}
        B -> {Y}
        C -> {X, Z}

    then B -> Y, which means that A cannot be Y, thus A must be X, and by the same logic
    C must be Z.
    """ # Find the alergen that only has one ingredient associated with it and pull it # out of the possibles dictionary, and remove the ingredient from all of the # other sets. # nobreak
possibles
Dict[K, Set[V]]