Next / Previous / Contents / Shipman's homepage

67. WordBank.mayBe(): Add one word choice to a slot

For each slot S, self.__choiceMap[S] is a set of the choices for slot S, as Word instances, and self.__wordToSlots[W] is the set of slots that have word W in their choices. We must also track the total number of choices in the whole puzzle, self.__totalChoices.

kkck
# - - -   W o r d B a n k . m a y B e

    def mayBe ( self, slot, word ):
        '''Add word as one choice for slot.
        '''
        #-- 1 --
        # [ if self.__choiceMap has an entry for (slot) ->
        #     self.__choiceMap  +:=  word
        #   else ->
        #     self.__choiceMap  :=  a new set containing word ]
        if VERBOSE: print "=== Slot %s may be %s" % (slot,word)
        self.__choiceMap[slot].add ( word )
        self.__wordToSlots[word].add ( slot )

        #-- 2 --
        self.__totalChoices += 1