Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

room101b

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?

  • one year ago
  • one year ago

  • This Question is Closed
  1. bwCA
    Best Response
    You've already chosen the best response.
    Medals 1

    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

    • one year ago
  2. room101b
    Best Response
    You've already chosen the best response.
    Medals 0

    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

    • one year ago
  3. room101b
    Best Response
    You've already chosen the best response.
    Medals 0

    yeh OCW 2008

    • one year ago
  4. bwCA
    Best Response
    You've already chosen the best response.
    Medals 1

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

    • one year ago
  5. rsmith6559
    Best Response
    You've already chosen the best response.
    Medals 0

    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"

    • one year ago
  6. bwCA
    Best Response
    You've already chosen the best response.
    Medals 1

    http://pyvideo.org/video/1738/good-enough-is-good-enough

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.