File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ from string import ascii_uppercase
2+
3+ from data import DICTIONARY , LETTER_SCORES
4+
5+
6+ def load_words ():
7+ """Load dictionary into a list and return list"""
8+
9+ with open (DICTIONARY ) as f :
10+ return [
11+ word .strip ()
12+ for word in f .read ().split ()
13+ ]
14+
15+
16+ def calc_word_value (word : str ):
17+ """Calculate the value of the word entered into function
18+ using imported constant mapping LETTER_SCORES"""
19+
20+ value = 0
21+
22+ for letter in word :
23+ letter = letter .upper ()
24+ if letter in ascii_uppercase :
25+ value += LETTER_SCORES [letter ]
26+
27+ return value
28+
29+ # return sum([
30+ # LETTER_SCORES[letter.upper()]
31+ # for letter in word
32+ # ])
33+
34+
35+ def max_word_value (list_of_words = load_words ()):
36+ """Calculate the word with the max value, can receive a list
37+ of words as arg, if none provided uses default DICTIONARY"""
38+
39+ biggest , biggest_word = 0 , None
40+
41+ for word in list_of_words :
42+ current_val = calc_word_value (word )
43+ if current_val > biggest :
44+ biggest = current_val
45+ biggest_word = word
46+
47+ return biggest_word
48+
49+
50+ # return max([
51+ # calc_word_value(word)
52+ # for word in list_of_words
53+ # ])
54+
55+
56+ if __name__ == "__main__" :
57+ pass
You can’t perform that action at this time.
0 commit comments