# - - - P u z z l e . _ _ r e d u c e S l o t
def __reduceSlot ( self, cell, slot, letterSet ):
'''Remove choices for a slot that don't have given letters.
[ (cell is a Cell in self) and
(slot is a Slot in self that contains cell) and
(letterSet is a set of one-character strings) ->
self.__wordBank := self.__wordBank - (choices for
slots whose characters at cell's position
are not in letterSet ]
'''
We first materialize the set of choices into a separate list, wordList. We'll also need to know the position (k) of the letter relative to the start of the slot;
that is computed by Section 59, “Slot.findCoord(): Puzzle position to
slot position”.
#-- 1 --
# [ wordList := list of word choices in self.__wordBank
# for slot, as a list of Word instances
# cellx := position of cell relative to slot ]
wordList = [ word
for word in
self.__wordBank.genSlotChoices ( slot ) ]
cellx = slot.findCoord ( cell.coord )
Next, work through wordList and, for each choice that
has a letter at the position cellx that is not in
letterSet, we remove it from the slot choices by
calling Section 68, “WordBank.isNot(): Remove one word from
a slot's list of choices”.
#-- 2 --
# [ self.__wordBank := self.__wordBank - (choices for slot
# that have letters in position cellx that are not in
# letterSet ]
for word in wordList:
#-- 2 body --
# [ if word[cellx] is not in letterSet ->
# self.__wordBank := self.__wordBank - (choice
# of word for slot)
if word[cellx] not in letterSet:
if VERBOSE:
print ( "*** Removing %s from %s because "
"word [%d] is not in %r." %
(word, slot, cellx, ''.join(list(letterSet))) )
self.__wordBank.isNot ( slot, word )