Learn python 3 dictionaires - Scrabble

I would like to get some feedback on the below:

letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
points = [1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 4, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10]

letter_to_points={key: value for key, value in zip(letters, points)}
letter_to_points[" "] = 0


def score_word(word):
  print_total = 0
  for letter in word:
    print_total += letter_to_points.get(letter,0)
  return print_total


player_to_words = {'BLUE': 'EARTH', 'TENNIS': 'EYES', 'EXIT':'MACHINE', 'TEST':'WORDNERD'}

player_to_points = {}

player = []
words = []
for player, words in player_to_words.items():
  player_points = 0
  for word in words:
    player_points += score_word(word)
  player_to_points[player] = player_points


I would like to check if the above is correct. on the lesson (https://www.codecademy.com/courses/learn-python-3/projects/scrabble) is says that the word: wordNerd should beat the other words by 1 however my output shows: {‘BLUE’: 8, ‘TENNIS’: 7, ‘EXIT’: 17, ‘TEST’: 16} where test is the key for WordNerd.

Hi there, I see the difference in for loop in line: letter_to_points.get(letter,0)
It should be letter_to_points[letter]

I am not a subscriber, so I can’t view the instructions of the project.

I think that the problem lies in:

player_to_words = {'BLUE': 'EARTH', 'TENNIS': 'EYES', 'EXIT':'MACHINE', 'TEST':'WORDNERD'}

If I am not mistaken, the player_to_words dictionary is supposed to have a structure like:

player_to_words = {'player1': [..., ..., ... ], 'wordNerd': [..., ..., ...], ...}

i.e. each key in the dictionary is supposed to be a player, and each value associated with that key is supposed to be a list of words played by that player.
for player, words in player_to_words.items():
for word in words:
loops seem to suggest this.

You should probably revisit the step where you were instructed on how to populate your player_to_words dictionary.


aah yes thank you! completely misread the instructions on that part! I’ll give it another go :slight_smile:

Works perfectly! thanks for helping :slight_smile:

1 Like

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