forked from pybites/challenges
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial copy from the template. * adding misc-files to my directory in order to test my code. * initial implementation passing all tests.
- Loading branch information
Showing
3 changed files
with
36 additions
and
3 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import os | ||
from data import DICTIONARY, LETTER_SCORES | ||
|
||
def load_words(): | ||
"""Load dictionary into a list and return list""" | ||
lines = [] | ||
dict_path = os.path.join(os.path.curdir, 'yoavcaspi', DICTIONARY) | ||
with open(dict_path, 'r') as f: | ||
lines = f.read().splitlines() | ||
return lines | ||
|
||
def calc_word_value(word): | ||
"""Calculate the value of the word entered into function | ||
using imported constant mapping LETTER_SCORES""" | ||
return sum(LETTER_SCORES[c.upper()] if c.isalpha() else 0 for c in word) | ||
|
||
def max_word_value(list_words = None): | ||
"""Calculate the word with the max value, can receive a list | ||
of words as arg, if none provided uses default DICTIONARY""" | ||
if list_words is None: | ||
list_words = load_words() | ||
max_word = None | ||
max_val = 0 | ||
for word in list_words: | ||
cur_val = calc_word_value(word) | ||
if cur_val > max_val: | ||
max_val = cur_val | ||
max_word = word | ||
return max_word | ||
|
||
|
||
if __name__ == "__main__": | ||
pass # run unittests to validate |