anonymous
  • anonymous
Having some difficulties with the 'update_hand' functionality of the word game on problem set 3. With this function are we supposed to be 'deleting' the elements of the dictionary 'hand' being used in 'word'? or are we just supposed to change the key-value pair from 'A':1 to 'A':0 (just an example)? if we are supposed to do the latter, does anyone have any idea how to go about that? i would like to try to do this without opening the solutions guide if possible... thanks!
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
katieb
  • katieb
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
from the docstring: """ ... returns the new hand, without those letters in it ...""" they provided a test suite for this PS. it has a function to test update_hand. when a coworker supplies you a test suite for code that you are writing, that is as good as a spec. you might want to look at that to help your understanding of the docstring. dictionaries have lots of methods. if using windows and idle, F1 will bring up the help file - it is an excellent resource, easier to use than the online version which is here: http://docs.python.org/2.7/library/stdtypes.html#mapping-types-dict
anonymous
  • anonymous
in 'update_hand' f(x). . u r nt gonna to delete the elements of the dictionary "hand" whose elements have been used to form words in "word" but u have to return a copy of the hand, containing only the letters remaining. For example: >>> hand = {'a':1, 'q':1, 'l':2, 'm':1, 'u':1, 'i':1} >>> displayHand(hand) # Implemented for you a q l l m u i >>> hand = updateHand(hand, 'quail') # You implement this function! >>> hand {'l': 1, 'm': 1} >>> displayHand(hand) l m
anonymous
  • anonymous
@bwCA- Thank you for the 'help' reference. I'll definitely do some digging in there. @moli1993- Thank you as well, this is helpful. after I return the 'updated' hand though, if I don't actually 'delete' the elements being used, how do I inform the 'deal_hand' how many additional letters to deal? OR am I completely mis-understanding this problem? Am I incorrect in my understanding of the game? Doesn't the player get dealt 7 letters initially, play a word, and then depending on how many letters they play get dealt 'x' additional letters to get their hand back to 7? or is it-- make as many words as you can with the 7 letters given, once you've played all words with those seven letters, then your 'hand' is done and you can deal an entirely new hand of 7? sorry I've been focusing so much on this one problem that I didn't really read through to the 'play hand' section yet.

Looking for something else?

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

More answers

anonymous
  • anonymous
you get one hand. you play it untill there are no letters left or you cannot make a word. the hand does not get 'refreshed' after you make a word.
anonymous
  • anonymous
makes so much more sense! Thank you
anonymous
  • anonymous
Ok guys- apparently I’m just slow. I'm still stuck on my update_hand function. I build a little function on the side for testing purposes and have attached it here. Right now the code is set up to print each chunk of iterations so that I can see what is happening to my 'hand' dictionary more easily. I thought I had it working, but when I changed my word from 'bad' to 'bab' it broke. It doesn't decrement the 'count' variable on the second time finding the letter from word matching the key of the dictionary. Also, I've got to be doing this in one of the most inefficient ways right? can anyone offer some pointers for my little snippet here to 1- help me figure out why it isn't decrementing like I think it should be, and 2- what can I do to completely overhaul this code and make it work better? Thanks again for your help- I'm very new to this and really appreciate any advice you can provide. hand = {'a':1,'b':2,'c':1,'d':1,'e':1} word = 'bab' def testit2(hand,word): for i, (count) in hand.items(): for j in word: if j == i: print 'correct letter ', ' J(',j,')=I(',i,')' hand[i] = count-1 else: print 'incorrect letter ', ' J(',j,')!=I(',i,')' print hand print return hand print testit2(hand,word)
anonymous
  • anonymous
never mind- cleaned up my code and it now works. Code below: but i'd still love to get some feedback on any other/better potential ways i could have accomplished this: hand = {'a':1,'h':1,'t':2,'b':2,'r':1} word = 'that' def testit(hand,word): for i,(count) in hand.items(): for j in word: if j == i: hand[i] -= 1 return hand print testit(hand,word)
anonymous
  • anonymous
please use a code pasting site like dpaste.com pastebin.com update_hand is not supposed to mutate the the hand object that is passed to it, yours does. also from the docstring: """...returns the new hand, without those letters in it....""" http://dpaste.com/1049425/ http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#use-in-where-possible-1

Looking for something else?

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