]> projects.mako.cc - wordplay-cdsw-solutions/blob - solution_9.py
1642ee8bf41f6b78dac7bc3033f5a83b102f879d
[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
27 for key in expensive_word:
28         print "{key}: {word}, {score}".format(key=key, word=expensive_word[key], score=expensive_word_score[key])
29          
30
31

Benjamin Mako Hill || Want to submit a patch?