Scrabble Project: Lowercase

Hey gang,

The final step of “Further Practice” asks the following:

(M)ake your letter_to_points dictionary able to handle lowercase inputs…

In the code below, I was able to change any input to my play_word() method to uppercase, but that feels decidedly different than doing something to my letter_to_points dictionary to make it able to handle lowercase inputs.

Thank you for the assistance!

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):
  point_total = 0
  for character in word:
    point_total += letter_to_points.get(character, 0)
  return point_total

player_to_words = {"player1": ["BLUE", "TENNIS", "EXIT"], "wordNerd": ["EARTH", "EYES", "MACHINE"], "Lexi Con": ["ERASER", "BELLY", "HUSKY"], "Prof Reader": ["ZAP", "COMA", "PERIOD"]}

player_to_points = {}

def update_point_totals():
  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


def play_word(player, word):
  player_to_words[player].append(word.upper())
  print(player_to_words)
  update_point_totals()
  print(player_to_points)

play_word("player1", "yellow")

Do you have a link to the project? I think you’re on the right lines anyway, perhaps just expand that thinking to the dictionary?

Hi Tim,

Here’s the link.

https://www.codecademy.com/paths/computer-science/tracks/cspath-cs-101/modules/cspath-python-dictionaries/projects/scrabble

Thank you!

Hmm, you make a good point. That does seem to be what the instruction is going for. Consider how you might this if it was all lowercase. I suppose you could just do that and the join in together with the original

letters = ["A", ...
points = [1, ...
1 Like

If you would rather avoid typing, you could use a string.

>>> alpha = 'abcdefghijklmnopqrstuvwxyz'
>>> alpha += alpha.upper()
>>> 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] * 2
>>> scores = dict(zip(alpha, points))

Yes, we can zip any two or more iterables.

>>> scores
{'a': 1, 'b': 3, 'c': 3, 'd': 2, 'e': 1, 'f': 4, 'g': 2, 'h': 4, 'i': 1, 'j': 8, 'k': 5, 'l': 1, 'm': 3, 'n': 4, 'o': 1, 'p': 3, 'q': 10, 'r': 1, 's': 1, 't': 1, 'u': 1, 'v': 4, 'w': 4, 'x': 8, 'y': 4, 'z': 10, 'A': 1, 'B': 3, 'C': 3, 'D': 2, 'E': 1, 'F': 4, 'G': 2, 'H': 4, 'I': 1, 'J': 8, 'K': 5, 'L': 1, 'M': 3, 'N': 4, 'O': 1, 'P': 3, 'Q': 10, 'R': 1, 'S': 1, 'T': 1, 'U': 1, 'V': 4, 'W': 4, 'X': 8, 'Y': 4, 'Z': 10}
>>> 

Considering that SCRABBLE has all upper case tiles do we need the lower case? Converting inputs and storing as upper case doesn’t seem like such a bad thing.

1 Like

Thank you, this is the clean method I couldn’t wrap my brain around.

1 Like