Next / Previous / Contents / Shipman's homepage

61. WordBank.__init__(): Constructor

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

    def __init__ ( self, puzzle ):
        '''Constructor
        '''
        self.puzzle = puzzle
        self.maxLen = 0
        self.__nWords = 0
        self.__totalChoices = 0
        self.__lenMap = defaultdict(set)
        self.__choiceMap = defaultdict(set)
        self.__wordToSlots = defaultdict(set)

For more information on the defaultdict type, see its import in Section 6, “Imports”. The self.__choiceMap will act like a dictionary in most respects, but if anyone references an entry that doesn't exist yet, the entry for that key will automatically be initialized as an empty Python set.