2020/16.py
def infer_one_to_one_from_possibles(possibles: Dict[K, Set[V]]) -> Dict[K, 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`` must be ``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 item that only has one possibility associated with it and pull it out
        # of the possibles dictionary, and remove the ingredient from all of the other
        # sets.
        for key, possible_fields in possibles.items():
            if len(possible_fields) == 1:
                inferred[key] = possible_fields.pop()
                remove_item = inferred[key]
                del possibles[key]
                break
        else:  # nobreak
            assert False, "No keys have a single possible value"

        for x in possibles:
            if remove_item in possibles[x]:
                possibles[x].remove(remove_item)

    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`` must be ``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:.




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 : .
def infer_one_to_one_from_possibles(possibles: Dict[K, Set[V]]) -> Dict[K, V]:
    inferred = {}
    while len(possibles):
        for key, possible_fields in possibles.items():
            if len(possible_fields) == 1:
                inferred[key] = possible_fields.pop()
                remove_item = inferred[key]
                del possibles[key]
                break
        else:  
            assert False, "No keys have a single possible value"
        for x in possibles:
            if remove_item in possibles[x]:
                possibles[x].remove(remove_item)
    return inferred
def infer_one_to_one_from_possibles ( possibles : Dict [ K , Set [ V ] ] ) -> Dict [ K , V ] : inferred = { } while len ( possibles ) : for key , possible_fields in possibles . items ( ) : if len ( possible_fields ) == 1 : inferred [ key ] = possible_fields . pop ( ) remove_item = inferred [ key ] del possibles [ key ] break else : assert False , "No keys have a single possible value" for x in possibles : if remove_item in possibles [ x ] : possibles [ x ] . remove ( remove_item ) 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`` must be ``Y``, which means that ``A`` cannot be ``Y``, thus ``A`` must be
    ``X``, and by the same logic ``C`` must be ``Z``.
    """ # Find the item that only has one possibility 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]]