File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 1+ from data import DICTIONARY , LETTER_SCORES
2+ from typing import Optional , List
3+
4+
5+ def load_words () -> List [str ]:
6+ """Load dictionary into a list and return list"""
7+ with open (DICTIONARY ) as f :
8+ return [line .strip () for line in f .readlines ()]
9+
10+
11+ def calc_word_value (word : str ) -> int :
12+ """Calculate the value of the word entered into function
13+ using imported constant mapping LETTER_SCORES"""
14+ return sum (LETTER_SCORES [letter ] for letter in list (word .replace ('-' , '' ).upper ()))
15+
16+
17+ def max_word_value (dictionary : Optional [List [str ]] = None ) -> str :
18+ """Calculate the word with the max value, can receive a list
19+ of words as arg, if none provided uses default DICTIONARY"""
20+ if dictionary is None :
21+ dictionary = load_words ()
22+ print ("crap:" , [x for x in dictionary if "-" in x ])
23+ return list (sorted (([calc_word_value (word ), word ] for word in dictionary ), reverse = True ))[0 ][1 ]
You can’t perform that action at this time.
0 commit comments