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

Im on ps5 problem 3 and i cant figure out why this wont work http://pastebin.com/eU3AhWuN

OpenStudy (anonymous):

maybe because your attempting to iterate through a dic when all you have is a list :(

OpenStudy (anonymous):

Your main problem is that you are not iterating through all the words in word_list. In other words, use a loop (hint ---> for loop). Also, you have forgotten to make sure that the word can be made with the letters in the current hand.

OpenStudy (anonymous):

I don't think has.key() works for lists I think it is only for dictionaries (that have keys).

OpenStudy (anonymous):

oops I didn't read your answer to yourself (in 3rd person...?) which says the same. double_o_seven suggests a good way to do it, you could also try bisection method if you are keen on it.

OpenStudy (anonymous):

'in' works for lists and dictionaries ... word in word_list

OpenStudy (anonymous):

bwCA is correct. The first test is is the word in the word list. A statemtent like "if not (word in word_list) : return false" will get your there. But, this is the easy part. The second test is to determine if the word is made up of letters in hand. For this I made a copy of hand. I Iterated though the letters in word and subtacted them out of the copy of hand. This is a scetchy explanation but hopefully it points in the right direction.

OpenStudy (anonymous):

Another approach is to convert the word to a dictionary using get_frequency_dict, and then compare the values of the indices of the two dictionaries "word" and "hand". e.g. word={'a':1, 'c':1, 't':1} and hand={'a':1,'b':1} then hand.get('c') < word.get('c') and therefore 'cat' isn't a valid word.

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!