Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 7 Online
OpenStudy (anonymous):

Hi, I've defined the pickBestWord method in ps10.py as follows. First I defined a getAnagramsDict methods for the wordList class which construct an anagram dictionary mapping strings consisting of alphabetically sorted letters (e.g., abc) to their anagrams (e.g., [cab,bac]). The pickBestWord method then runs through the possible prefix of the alphabetically sorted hand, looks up the anagram dictionary for each of these prefixes and extracts the corresponding anagrams. The best scoring anagram is then returned. At least that's the plan. However when a string does not occur in the anagram dictionary, the program fails. I do not understand why the for loop does not continue with the next possible suffix (next i value in the code) ? Here is the code: http://dpaste.com/hold/757136/

OpenStudy (anonymous):

Hmm... I think it's because of the range of your for loop... You should check it :)

OpenStudy (anonymous):

maybe try adding 'else: continue' ?

OpenStudy (anonymous):

The range was ok and the else: continue did not solve the issue (whether I add it or not, I get the same behavious). In fact the problem was simply that my pickBestWord was outputing a tuple rather than a word score and so getWordScore(p.pickBestWord(wordlist)) failed (in ps10_test.py) . The code was also wrong in that I only tested ordered prefixes of the hand while all subsets must be tested. Here is the modified code. http://dpaste.com/hold/759524/

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!