Skip to content

Commit

Permalink
PCC01 Fuzzygwalchmei (pybites#595)
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzygwalchmei authored and pmayd committed Oct 2, 2019
1 parent 3de079e commit 1f8e6c4
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions 01/fuzzygwalchmei/wordvalue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from data import DICTIONARY, LETTER_SCORES

def load_words():
"""Load dictionary into a list and return list"""
return [line.rstrip('\n') for line in open(DICTIONARY)]

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(letter.upper(), 0) for letter 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

0 comments on commit 1f8e6c4

Please sign in to comment.