I'm working on ps3, problem 3 (def is_valid_word) and I'm a little stuck. Rather than looking at the solution, I was hoping to get some hints. I am trying to break down the solution into logical steps. Given a word_list, a word='string' and a hand={dictionary}, I need to write a function (def is_valid_word) that checks if the is valid i.e. word must be in word_list and the word must be made up of letters in the hand. So far I have: 1 - check if word is in word_list (easy) 2 - check if each letter in word is in hand (easy) 3 - if each letter in word is in hand, are there enough of each letter in hand to make word (hmm...) Should I be converting the word from a string to a dictionary, in order to compare the frequency of each letter in word and hand? Or updating the hand as I check for each letter? Hints not solution please!!!
there are a number of ways to solve this "Should I be converting the word from a string to a dictionary, in order to compare the frequency of each letter in word and hand?" that will work " Or updating the hand as I check for each letter?" hmmm .. do the instructions say anything about mutating hand? you would have to be careful but this would work. sounds like you know what to do - write them both and play around with them and see which one you like best. you may even think of a different way to do it while doing all of that. this string method might help - http://docs.python.org/2.7/library/stdtypes.html#str.count which takes longer: determining if hand can make the word or finding out if the word is in the wordlist?
Thanks bwCA, I kept at it and finally my code passes the test! I would be interested to know who long others have spent on problem set 3. It has taken me over 10 hours to get through it...curious to know if this is normal. I find it hard to believe that such long assignments would be given to students with a full course load. Of course in my case, I'm only taking one class and going at my own pace. But if I was getting assignments like these as a full time student I would be struggling. Although perhaps as a full time computer science major my coding skills would be coming along quicker and I would be relying more on teamwork. That being said, thanks for responding me and letting me know that I was on the right track.
i spent a lot of time on all the problems because i went off on tangents to the topics being covered and did a lot of reading and playing around. the more you practice, the easier it becomes - some of the problems seem easier to solve than others.
Join our real-time social learning platform and learn together with your friends!