File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ from data import DICTIONARY , LETTER_SCORES
2
+
3
+ def load_words ():
4
+ """Load dictionary into a list and return list"""
5
+ with open (DICTIONARY , 'r' ) as dict_file :
6
+ dictionary = dict_file .read ().splitlines ()
7
+ return dictionary
8
+
9
+ def calc_word_value (word ):
10
+ """Calculate the value of the word entered into function
11
+ using imported constant mapping LETTER_SCORES"""
12
+ score = 0
13
+ for char in word .upper ():
14
+ if char .isalpha ():
15
+ score += LETTER_SCORES [char ]
16
+ return score
17
+
18
+ def max_word_value (word_list = load_words ()):
19
+ """Calculate the word with the max value, can receive a list
20
+ of words as arg, if none provided uses default DICTIONARY"""
21
+ max_score = ('' , 0 )
22
+ for word in word_list :
23
+ score = calc_word_value (word )
24
+ if score > max_score [1 ]:
25
+ max_score = (word , score )
26
+ return max_score [0 ]
27
+
28
+ if __name__ == "__main__" :
29
+ pass # run unittests to validate
You can’t perform that action at this time.
0 commit comments