Whitespace corrections, a couple bug fixes, replacing a format string with constructi...
[wordplay-cdsw-solutions] / solution_9.py
1 import scrabble
2
3 # Make a list of the highest scoring word that starts with each letter.
4
5 # This is a bit more advanced, but you already know how to do every single piece of this.
6
7 # This only returns 1 word with the given score.
8
9 expensive_word = {}
10 expensive_word_score = {}
11
12 for word in scrabble.wordlist:
13     first_letter = word[0]
14     if first_letter not in expensive_word:
15         expensive_word[first_letter] = ''
16         expensive_word_score[first_letter] = 0
17
18     score = 0
19     for char in word:
20         score = score + scrabble.scores[char]
21
22     if expensive_word_score[first_letter] < score:
23         expensive_word[first_letter] = word
24         expensive_word_score[first_letter] = score
25
26 for key in expensive_word:
27     print(key + ": " + expensive_word[key] + ", " + str(expensive_word_score[key]))

Benjamin Mako Hill || Want to submit a patch?