Skip to content

Commit 464d542

Browse files
authored
Merge pull request #783 from LaneHesser/PCC01
PCC01 LaneHesser
2 parents 20e051e + 2dfb140 commit 464d542

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

01/LaneHesser/wordvalue.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from string import ascii_uppercase
2+
3+
from data import DICTIONARY, LETTER_SCORES
4+
5+
6+
def load_words():
7+
"""Load dictionary into a list and return list"""
8+
9+
with open(DICTIONARY) as f:
10+
return [
11+
word.strip()
12+
for word in f.read().split()
13+
]
14+
15+
16+
def calc_word_value(word: str):
17+
"""Calculate the value of the word entered into function
18+
using imported constant mapping LETTER_SCORES"""
19+
20+
value = 0
21+
22+
for letter in word:
23+
letter = letter.upper()
24+
if letter in ascii_uppercase:
25+
value += LETTER_SCORES[letter]
26+
27+
return value
28+
29+
# return sum([
30+
# LETTER_SCORES[letter.upper()]
31+
# for letter in word
32+
# ])
33+
34+
35+
def max_word_value(list_of_words=load_words()):
36+
"""Calculate the word with the max value, can receive a list
37+
of words as arg, if none provided uses default DICTIONARY"""
38+
39+
biggest, biggest_word = 0, None
40+
41+
for word in list_of_words:
42+
current_val = calc_word_value(word)
43+
if current_val > biggest:
44+
biggest = current_val
45+
biggest_word = word
46+
47+
return biggest_word
48+
49+
50+
# return max([
51+
# calc_word_value(word)
52+
# for word in list_of_words
53+
# ])
54+
55+
56+
if __name__ == "__main__":
57+
pass

0 commit comments

Comments
 (0)