Next / Previous / Contents / Shipman's homepage

66. WordBank.genCandidates(): What words have a given length?

kkck
# - - -   W o r d B a n k . g e n C a n d i d a t e s

    def genCandidates ( self, n ):
        '''Generate all words of length n.
        '''
        #-- 1 --
        # [ wordList  :=  the words from self.__lenMap[n] as a
        #                 list of Word instances ]
        wordList = list ( self.__lenMap[n] )

As a convenience in debugging, we'll generate the words in ascending order.

kkck
        #-- 2 --
        # [ wordList  :=  wordList sorted into ascending order ]
        wordList.sort()

        #-- 3 --
        for word in wordList:
            yield word

        #-- 4 --
        raise StopIteration