I have been working on a Scrabble Word Finder for a couple of days now and have it working pretty much but would love to improve the efficiency.The code is made up of 2 classes: one for creating and managing a pool of letter tiles and another for iterating over a word dictionary (from a .txt file) to check/score word matches in the letter rack (from the tile pool) and a cross letter. As I mentioned, everything works so far, but I feel like it could be faster. I have tried taking advantage of generators but am running into problems with them in the WordFinder class as I am not very experienced in them. I will post my code as well as the code I am using to test it.scrabble_challenge.py (My Code)import csvimport randomclass TilePool(list):    def __init__(self):                Initializes the Tile Pool by reading the given 'tile.csv' file and converting it into a tile pool list with one        list item per tile based on the amount of tiles for each letter                # Open csv file        with open(tiles.csv) as f:            # Read csv into list of lists of each lines values            tiles_csv = csv.reader(f, delimiter=,)            # Convert the list into a tile pool            list.__init__(self, ((line[0], line[1])                                 for line in tiles_csv if len(line[0]) == 1                                 for x in xrange(int(line[2]))))            del tiles_csv    def pop(self, tile_count=None):                Returns a list of tiles from the tile pool based on the amount specified in the 'tile_count' parameter and the        amount of tiles left in the pool.        :param tile_count: The amount of tiles desired (If not specified up to 7 tiles will be returned)        :return: A new list of tiles from tile pool                assert len(self), # Tile Pool is empty        # When the tile count is None return (up to) 7 tiles        if tile_count is None:            tile_count = 7        assert tile_count in xrange(1, 8), # Tile Count must be between 1 and 7        new_tiles = []        counter = 1        while len(self) and counter <= tile_count:  # Return tiles while tile pool has tiles AND tile count not reached            rand_choice = random.choice(self)  # Get a random tile            new_tiles.append(rand_choice)  # Add it to new_tiles list            self.remove(rand_choice)  # Delete it from pool            counter += 1        return new_tiles    def view_pool(self):                Prints each tile in the pool with it's 'Score' value        :return: None                assert len(self), # Tile Pool is empty        for tile in self:            print({letter}: {score}.format(letter=tile[0], score=tile[1]))class WordFinder:    def list_words(self, letters, cross_letter):        if cross_letter is None:                cross_letter = ''        with open(word_dictionary.txt) as x:            word_dict = (line.strip() for line in x)            accepted = []            for word in word_dict:                if cross_letter in word:                    min_cross = list(word.replace(cross_letter, '', 1))                    score = 0                    for letter in letters:                        if not min_cross:                            accepted.append((word, score))                            break                        elif letter[0] in min_cross:                            min_cross.remove(letter[0])                            score += int(letter[1])            return acceptedtesting_code.pyimport sysimport scrabble_challengedef main():    cross_letters = [chr(x) for x in xrange(97, 123)]    cross_letters.insert(0, None) # the first word has no cross letter    tile_pool = scrabble_challenge.TilePool()    word_finder = scrabble_challenge.WordFinder()    while len(tile_pool):        letters = tile_pool.pop()        for cross_letter in cross_letters:            for word, score in word_finder.list_words(letters, cross_letter):                print word, score    return 0if __name__=='__main__':    sys.exit(main())I would like to have some way of initializing the word_dict generator in the __init__ so it isn't being generated in every loop in my testing_code.py. But when I tried adding this:with open(word_dictionary.txt) as x:    word_dict = (line.strip() for line in x)in the __init__ I would get a ValueError: I/O operation on closed file error. But this structure works on the list comprehension in class TilePool.I'd also like to get the list_words method to yield as opposed to return. My attempts at both of these have failed. Any other code efficiency suggestions (for scrabble_challenge.py) are certainly welcome.
Scrabble word finder
python;performance;generator