Skip to content

Commit c26f3c0

Browse files
tetrismegistuspybites
authored andcommitted
Challenge 1 Submission (pybites#59)
* completed challenge 01 * PCC1 tetrismegistus * Delete wordvalue.py
1 parent 3bd79e1 commit c26f3c0

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

01/tetrismegistus/wordvalue.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from data import DICTIONARY, LETTER_SCORES
2+
3+
def load_words():
4+
"""Load dictionary into a list and return list"""
5+
with open(DICTIONARY, 'r') as dict_file:
6+
dictionary = dict_file.read().splitlines()
7+
return dictionary
8+
9+
def calc_word_value(word):
10+
"""Calculate the value of the word entered into function
11+
using imported constant mapping LETTER_SCORES"""
12+
score = 0
13+
for char in word.upper():
14+
if char.isalpha():
15+
score += LETTER_SCORES[char]
16+
return score
17+
18+
def max_word_value(word_list=load_words()):
19+
"""Calculate the word with the max value, can receive a list
20+
of words as arg, if none provided uses default DICTIONARY"""
21+
max_score = ('', 0)
22+
for word in word_list:
23+
score = calc_word_value(word)
24+
if score > max_score[1]:
25+
max_score = (word, score)
26+
return max_score[0]
27+
28+
if __name__ == "__main__":
29+
pass # run unittests to validate

0 commit comments

Comments
 (0)