Skip to content

Commit

Permalink
Challenge 1 Submission (pybites#59)
Browse files Browse the repository at this point in the history
* completed challenge 01

* PCC1 tetrismegistus

* Delete wordvalue.py
  • Loading branch information
tetrismegistus authored and pybites committed Jul 25, 2017
1 parent 3bd79e1 commit c26f3c0
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions 01/tetrismegistus/wordvalue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from data import DICTIONARY, LETTER_SCORES

def load_words():
"""Load dictionary into a list and return list"""
with open(DICTIONARY, 'r') as dict_file:
dictionary = dict_file.read().splitlines()
return dictionary

def calc_word_value(word):
"""Calculate the value of the word entered into function
using imported constant mapping LETTER_SCORES"""
score = 0
for char in word.upper():
if char.isalpha():
score += LETTER_SCORES[char]
return score

def max_word_value(word_list=load_words()):
"""Calculate the word with the max value, can receive a list
of words as arg, if none provided uses default DICTIONARY"""
max_score = ('', 0)
for word in word_list:
score = calc_word_value(word)
if score > max_score[1]:
max_score = (word, score)
return max_score[0]

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

0 comments on commit c26f3c0

Please sign in to comment.