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

Just finished the first part of problem set 5. Can anyone take a look and let me know what they think? It's posted here; http://codepad.org/c3tCYeil Thanks in advance, -Ian

OpenStudy (anonymous):

Your code looks good, commented, and at least glancing over it seems to work just fine. One minor (nit picky) improvement I would point out is this: for letter in word_dict: if not hand.has_key(letter) or word_dict[letter] > hand[letter]: return False You don't need to use the comparison operator with boolean values (if not foo is considered more pythonic), and both statements return false, why would you add an elif? But I didn't try it out yet, just a snippet really.

OpenStudy (anonymous):

The elif was there because I didn't even consider the 'or' operator. Duh. The other bit comes from the fact that I'm trying to learn C and C++ at the same time, so sometimes my styles collide, and since I can't say if not foo in C++, well, I just don't anywhere unless I put a bit of thought into it. Made those changes and seems like it works fine, and the nit picky stuff is the stuff I want to hear about. Easy to read code is generally easy to debug and easy to maintain, so beating that into my head now is important to me.

OpenStudy (anonymous):

I know how that feels (damn semi-colons :-D), but after a while, I also believe that acquiring some language's idioms is a good thing, if you don't abuse them (like using not for something that is not a boolean value). You have the not operator in C, the bang, but I am unsure whether or not it exists on C++ (but likely yes). The not operator in C returns the boolean NOT result(-1 returns 0, 0 returns 1, 1 returns 0, etc).

OpenStudy (anonymous):

the following are just my preferences, nothing wrong with what you wrote: At line 156 i would have used "if word not in word_list:" for lines 158 thru 162 - for letter, count in word_dict.iteritems(): if hand.get(letter, 0) < count: return False and lines 108&112- x = random.choice(VOWELS) x = random.choice(CONSONANTS)

OpenStudy (anonymous):

I didn't even know "if word not in word_list" was an actual expression. It sounds too, well, real. :)

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!