Learn Python 3 project: scrabble, allowing lowercase inputs

I am working on the scrabble project:https://www.codecademy.com/courses/learn-python-3/projects/scrabble

The last optional step is to " * make your letter_to_points dictionary able to handle lowercase inputs as well"

My proposed solution to this was to create a dictionary with key:value pairs with the lowercase letters and then merge that list with the original which contained all uppercase characters.

However my final bit of code:

letters_to_points = letters_to_points.update(lower_letters_to_points)

If i run

print(letters_to_points)

it returns none.

I’m curious as to that is returning none, from my understand .update() can be used to merge two dictionaries.

Full code 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]
#print(type(letters) is list)

def lower_the_letters(list_):
  list_lowered = []
  if type(list_) is list:
    for string in letters:
      list_lowered.append(string.lower())
  else:
      list_lowered = 'NOT A LIST'
  return list_lowered

letters_to_points = {value:key for key, value in zip(points,letters)}

lower_letters_to_points = {value:key for key, value in zip(points,lower_the_letters(letters))}

letters_to_points = letters_to_points.update(lower_letters_to_points)

Like a few other similarly styled methods (e.g. append, extends and similar) this one is not designed to return anything. Instead it alters an existing dictionary-
https://docs.python.org/3/library/stdtypes.html#dict.update

2 Likes

That makes sense, thank you!

1 Like

Im completely lost on the concept of using a for loop to add the lower case letters to the dictionary. Can someone please assist me?

The most elegant solution seems to be just using the .upper method for letter in the score_word function:

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)} def score_word(word): point_total = 0 for letter in word: point_total += letter_to_points.get(letter.upper(), 0) return point_total brownie_points_lower = score_word("brownie") brownie_points_upper = score_word("BROWNIE") brownie_points_alternating = score_word("BrOwNiE") print(brownie_points_lower) print(brownie_points_upper) print(brownie_points_alternating)

Whether it’s “BROWNIE”, “brownie” or “BrOwNiE”, the end result is that it gets checked against the characters in upper case in the dictionary. So even though the Codecademy solution of just duplicating everything is viable, to me it felt excessive.

2 Likes