week3/crossword/generate.py
def enforce_node_consistency(self):
        """
        Update `self.domains` such that each variable is node-consistent.
        (Remove any values that are inconsistent with a variable's unary
         constraints; in this case, the length of the word.)
        """
        for variable, words in self.domains.items():  # Iterate over all variables and their potential words
            words_to_remove = set()  # Set to store words that will be removed from the variable's potential words
            for word in words:
                if len(word) != variable.length:  # If word is not of the same length as the variable can hold, delete
                    words_to_remove.add(word)
            # Subtract the words that are unsuitable from variable's domain
            self.domains[variable] = words.difference(words_to_remove)

        Update `self.domains` such that each variable is node-consistent.
        (Remove any values that are inconsistent with a variable's unary
         constraints; in this case, the length of the word.)
        
Update `self.domains` such that each variable is node-consistent.
(Remove any values that are inconsistent with a variable's unary
constraints; in this case, the length of the word.)
Update ` self . domains ` such that each variable is node - consistent . ( Remove any values that are inconsistent with a variable ' s unary constraints ; in this case the length of the word . )
def enforce_node_consistency(self):
        for variable, words in self.domains.items():  
            words_to_remove = set()  
            for word in words:
                if len(word) != variable.length:  
                    words_to_remove.add(word)
            self.domains[variable] = words.difference(words_to_remove)
def enforce_node_consistency ( self ) : for variable , words in self . domains . items ( ) : words_to_remove = set ( ) for word in words : if len ( word ) != variable . length : words_to_remove . add ( word ) self . domains [ variable ] = words . difference ( words_to_remove )
Update `self.domains` such that each variable is node-consistent.
Update ` self . domains ` such that each variable is node - consistent .
"""
        Update `self.domains` such that each variable is node-consistent.
        (Remove any values that are inconsistent with a variable's unary
         constraints; in this case, the length of the word.)
        """ # Iterate over all variables and their potential words # Set to store words that will be removed from the variable's potential words # If word is not of the same length as the variable can hold, delete # Subtract the words that are unsuitable from variable's domain
self