In my review of my functions I realized that I took a different angle to the next part of this problem set.  The problem asks you to ‘...change the implementation of is_valid_word to take as an argument the representation you created above rather than the word_list itself.’ (page 4)  Here they want you to alter the is_valid_word() function so that it can not only verify that the word submitted is contained in the word_list, but also that uses the points_dict variable that was created.  Then as an answer it is supposed to spit out that the word is accurate and what its point value is.

Suffice it to say, I didn’t do this at all.  I still ran is_valid_word() separately and used the points_dict variable to handle any point creation.  Because I did not combine the two, it made some of my later adjustments, perhaps, more complicated.  My apologies in advance for any ridiculous looking code.

The next function I created is a generator for the computer player, that will create combinations of letters based on the hand.  To do this I implemented a brute force algorithm.  Typically brute force algorithms are very poor choices, unless the information you’re processing is minimal.  My function is shown below, it’s recursive.

 def comb(chosen, available):    finallist = [chosen,]    for a in available:        newavail = available[:]        newavail.remove(a)        finallist += comb(chosen + [a,], newavail)    return finallist

This function creates a new list (of lists) called finallist, that returns all possible combinations from the letters provided in the hand.  It starts off by going through each letter in available (which is the same as hand).  For each letter it creates a new combination of letters by taking a slice, removing the letter being processed, then adding a new list to the finallist by recursively calling itself.  Once completed this returns a list of lists, that might look something like this: ((‘a’,’b’,’c’), (‘b’,’c’), (‘a’,’c’), (‘a’)).  This example is not fully complete, because it does not show all possible combinations or different ways in which the letters could be organized.

Up Next Time: Problem Set 6; Problem 3 of 5, Part 3