9. scrabble_score - trouble with a "sledgehammer" approach


9. scrabble_score

This lesson has been tricky for me, much like the lesson before it. What I have so far seems to be working at least part-way through the problem, but throws the error "'a' is not in list."

I have two questions about this: first, which list?! We're working with dictionaries here. Second, can anyone pinpoint where my code is getting hung up? I'm pretty sure it's not cycling all the way through the string before it throws the error, but it also may be and is just not recognizing that 'a' is in the dictionary?

score = {"a": 1, "c": 3, "b": 3, "e": 1, "d": 2, "g": 2, 
         "f": 4, "i": 1, "h": 4, "k": 5, "j": 8, "m": 3, 
         "l": 1, "o": 1, "n": 1, "q": 10, "p": 3, "s": 1, 
         "r": 1, "u": 1, "t": 1, "w": 4, "v": 4, "y": 4, 
         "x": 8, "z": 10}

def scrabble_score(word):
    user_score = 0
    word = word.lower()
    for i in word:
        for i in dict(score):
            user_score == score.values().index(i) + user_score
    return user_score


No need for this inner loop. You already have a letter in the key variable. Just look up that letter.

user_score += score[i]

We can forego the obvious (otherwise) error.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.