Next / Previous / Contents / Shipman's homepage

62. WordBank.addWord(): Add a word to the word list

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

    def addWord ( self, rawWord ):
        '''Add a word to the bank.
        '''

When a word is added, we must perform several operations:

kkck
        #-- 1 --
        # [ word  :=  a Word instance made from rawWord ]
        word = Word ( rawWord )

        #-- 2 --
        # [ self.maxLen  :=  max ( self.maxLen, len(word) )
        #   self.__nWords  +:=  1
        #   self.__lenMap[len(word)]  +:=  word ]
        self.maxLen = max ( self.maxLen, len(word) )
        self.__nWords += 1
        if word in self.__lenMap[len(word)]:
            raise SyntaxError ( "Duplicate word '%s'." % word )
        self.__lenMap[len(word)].add ( word )