Skip to content

Commit

Permalink
PCC01 mandyedi (pybites#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
mandyedi authored and pybites committed May 4, 2018
1 parent f3210a3 commit 4b612f8
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions 01/mandyedi/wordvalue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from data import DICTIONARY, LETTER_SCORES

def load_words():
"""Load dictionary into a list and return list"""
with open('./../dictionary.txt') as f:
words = f.read().splitlines()
return words

def calc_word_value(word):
"""Calculate the value of the word entered into function
using imported constant mapping LETTER_SCORES"""
score = 0
for letter in word:
if letter.isalpha():
score += LETTER_SCORES[letter.upper()]
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"""
if words is None:
words = load_words()
maxValue = 0
maxWord = None
for word in words:
currentMax = calc_word_value(word)
if currentMax > maxValue:
maxValue = currentMax
maxWord = word
return maxWord

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

0 comments on commit 4b612f8

Please sign in to comment.