Next / Previous / Contents / Shipman's homepage

68. WordBank.isNot(): Remove one word from a slot's list of choices

kkck
# - - -   W o r d B a n k . i s N o t

    def isNot ( self, slot, word ):
        '''Remove word from the set of choices for slot.
        '''

There is no guarantee that word is currently a choice for slot; if it isn't, simply return. Otherwise, we must remove that word from the slot's set and also decrement the self.__totalChoices counter.

kkck
        #-- 1 --
        # [ choiceSet  :=  the set of choices for slot ]
        choiceSet = self.__choiceMap[slot]

        #-- 2 --
        if word not in choiceSet:
            return
        else:
            self.__totalChoices -= 1

        #-- 3 --
        # [ self.__choiceMap  :=  self.__choiceMap with choice
        #       word removed from the set for key (slot)
        #   self.__wordToSlots  :=  self.__wordToSlots with
        #       slot removed from the set for key (word) ]
        self.__choiceMap[slot].remove ( word )
        self.__wordToSlots[word].remove ( slot )
        if VERBOSE: print "=== Slot %s is not %s" % (slot,word)