Skip to content

Commit

Permalink
PCC01 mh70cz (pybites#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
mh70cz authored and pybites committed Sep 15, 2018
1 parent e980331 commit d443cc1
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions 01/mh70cz/wordvalue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from data import DICTIONARY, LETTER_SCORES

def load_words():
"""Load dictionary into a list and return list"""
dl = []
with open(DICTIONARY) as f:
for line in f:
dl.append(line.strip())
return dl

def calc_word_value(word):
"""Calculate the value of the word entered into function
using imported constant mapping LETTER_SCORES"""
score = 0
for l in word:
l = l.upper()
score += LETTER_SCORES.get(l, 0)
return score


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"""
max_val = 0
max_val_word = None
if words is None:
words = load_words()
for w in words:
val = calc_word_value(w)
if val > max_val:
max_val_word = w
max_val = val
return max_val_word



if __name__ == "__main__":
pass # run unittests to validate

0 comments on commit d443cc1

Please sign in to comment.