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.
* PCC01 ryanh153 * Delete dictionary.txt This file is not part of your solution and rather big. You don't have to commit files of the original challenge :) * Delete wordvalue-template.py Again, you don't have to add template files to your solution, just your solution :) * Delete data.py This file is part of the challenge and not your code so I deleted it from the PR * Delete test_wordvalue.py Tests are part of the challenge and not your contribution so I deleted them from the pR :)
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
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,5 @@ | ||
## Code Challenge 01 - Word Values Part I | ||
|
||
Instructions [here](http://pybit.es/codechallenge01.html). | ||
|
||
Previous challenges and About [here](http://pybit.es/pages/challenges.html). |
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,31 @@ | ||
from data import DICTIONARY, LETTER_SCORES | ||
|
||
"""Load dictionary into a list and return list""" | ||
def load_words(): | ||
|
||
with open(DICTIONARY,'r') as dicFile: | ||
dictionary = dicFile.readlines() | ||
|
||
dictionary = [word.strip() for word in dictionary] | ||
|
||
return dictionary | ||
|
||
|
||
"""Calculate the value of the word entered into function | ||
using imported constant mapping LETTER_SCORES""" | ||
def calc_word_value(word): | ||
return sum([LETTER_SCORES[char] for char in word.upper() if char in LETTER_SCORES.keys()]) | ||
|
||
|
||
"""Calculate the word with the max value, can receive a list | ||
of words as arg, if none provided uses default DICTIONARY""" | ||
def max_word_value(words=None): | ||
if words == None: | ||
words = load_words() | ||
|
||
scores = [calc_word_value(word) for word in words] | ||
|
||
return words[scores.index(max(scores))] | ||
|
||
if __name__ == "__main__": | ||
pass # run unittests to validate |