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

Hi, I'm on problem set 5 problem 6: implementing the game 'ghost'. I have two questions. 1) The 'Helper Code' includes a function to convert the string to a dictionary, is it easier to work with dictionaires in this problem and why? 2) A rule in the game is that players must create word fragments that can become words, how do I search the wordlist to check this?

OpenStudy (anonymous):

MIT OCW 2008?? my solution does not use the frequency dictionary function the startswith() string method may be usefull. I used a bisection search of the wordlist to see if a fragment could make a word http://docs.python.org/2.7/library/stdtypes.html#str.startswith

OpenStudy (anonymous):

I used the str.startswith and it worked. I haven't done a bisection of the wordlist because I found that an answer was return straight away with "any (w.startswith(frag) for w in wordlist)". although I imagine a bisect seach would be more efficient

OpenStudy (anonymous):

yeh OCW 2008

OpenStudy (anonymous):

keep it simple, if it works and its not to slow it's ok. nice generator.

OpenStudy (rsmith6559):

1) Dictionaries are a mapping between a key and a value. Your variables are actually a dictionary: foo = 3 foo is the key, 3 is the value. When you want foo's value, you just refer to foo. Most of the rest of it is just syntax stuff. One thing that isn't much fun with dictionaries, if you refer to a key that doesn't exist, they raise an exception. The good news, is that dictionaries have method to query them that won't raise an exception: foo = dict.get( key, sentinalValue ) if( foo == sentinalValue ): print "shucks!" else: print "you got key's value"

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!