A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 4 years ago

PS#6, problem 4: I am having a hard time understanding what it is asking me to do. Is it asking me to find all possible permutations in a hand and call it rearrange_dict, then passing each key through is_valid_word? I was able to do problem 3 fine code is below just in case I approached it wrong (which may be the reason I don't understand what is asked in problem 4). Please help! http://codepad.org/1RSxtXDm

  • This Question is Closed
  1. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    alwahsh posted some code below. So did I.

  2. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    rearrange dictionary keys are the sorted words and the values are the words {sorted(word) : word} 'alpha' --> {'aahlp' : 'alpha'} then you can say something like find the highest scoring key in the rearranged dictionary that is a sorted(subset) of hand or for every sorted(subset) of hand which corresponding rearranged dictionary key has the highest value

  3. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    not entirely sure what is going on or why sorting each word first makes it faster.... Will go struggle a little longer and read through the older posts. Thanks!

  4. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    it's faster because the dictionary is accessed in constant time (I believe). so here are the steps (and example with 'hunt'): -sort the word: e.g. hntu -create all the subsets of the sorted word: e.g. h, n, hn, t, th, tn, thn, u, uh, un, uhn,ut,uth,utn,uthn -now you have a list with 15 elements (2**4 -1) -iterate over the 15 elements to find the highest score. since you already have the rearranged_dict, you're just plugging in the subsets as the keys. iterating through 15 elements is faster than iterating through the whole dictionary every time.

  5. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    in the previous problem you should have had to test all the (subset) permutations of hand to find the best word. you have to look for 'aac' and 'aca' and 'caa' with the rearranged dictionary the keys are sorted so a word that contains the letters a, a, and you only have to use (sorted) combinations of hand ('aac' only) and there are a lot less combinations than permutations. hope that made sense

  6. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I didn't use permutations on the previous problem which is probably why I was having difficulty grasping how sorting it like the pset suggested was going to make it faster as I didn't see how I was going to avoid looping through the whole wordfile at least once. But between the both of you, I think it is crystal clear what is being asked. Thanks!

  7. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    you shouldn't have to loop. you can use the in or not in operators http://docs.python.org/reference/expressions.html#in

  8. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    nope didn't need to loop after all the help I got from you guys - so thanks for that!. Only looped once through the list of combinations rather than the whole dictionary

  9. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

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.