diff --git a/01/ananda23-cs/wordvalue.py b/01/ananda23-cs/wordvalue.py new file mode 100644 index 00000000..7f1ae96f --- /dev/null +++ b/01/ananda23-cs/wordvalue.py @@ -0,0 +1,21 @@ +from data import DICTIONARY, LETTER_SCORES + +def load_words(): + """Load dictionary into a list and return list""" + with open(DICTIONARY) as f: + return f.read().split() + +def calc_word_value(word): + """Calculate the value of the word entered into function + using imported constant mapping LETTER_SCORES""" + return sum(LETTER_SCORES.get(char.upper(), 0) for char in word) + +def max_word_value(words=None): + """Calculate the word with the max value, can receive a list + of words as arg, if none provided uses default DICTIONARY""" + if words is None: + words = load_words() + return max(words, key=calc_word_value) + +if __name__ == "__main__": + pass # run unittests to validate \ No newline at end of file