views:

37

answers:

2

The function class:

def play_best_hand(hand, wordDict):

tempHand = hand.copy()
points = 0
for word in wordDict:
    for letter in word:
        if letter in hand:
            tempHand[letter] = tempHand[letter] - 1 
            if tempHand[letter] < 0:
                return False
            if wordDict[word] > points:
                bestWord == word
                points = wordDict[word]
return bestWord

Here is my trackback error. Line 209 corresponds to the line 'for word in wordDict'

 Traceback (most recent call last):
    File "ps6.py", line 323, in <module>
    play_game(word_list)
  File "ps6.py", line 307, in play_game
    play_hand(hand.copy(), word_list)
  File "ps6.py", line 257, in play_hand
    guess = play_best_hand(hand, wordDict)
  File "ps6.py", line 209, in play_best_hand
    for word in wordDict:
TypeError: 'NoneType' object is not iterable
+2  A: 

This means that the variable wordDict is None instead of a dictionary. This means there's an error in the function that calls play_best_hand. Probably, you forget to return a value in a function, so it returns None?

leoluk
Got 'er fixed after I started hunting!Thanks!
NoahClark
Why would letter be a bool?
NoahClark
+2  A: 

In the play_best_hand() function you have:

if wordDict[word] > points:
    bestWord == word

You probably meant to do an assignment instead of comparing for equality:

if wordDict[word] > points:
    bestWord = word
sth
That is correct. Although, it didn't fix the issue.
NoahClark
@Noah Clark: Probably even with this corrected it can happen that `bestword` isn't set to anything before it is returned. (For example it happens if `wordDict` is empty or if `hand` is an empty string.)
sth