Skip to content

Commit

Permalink
PCC01 ryanh153 (pybites#571)
Browse files Browse the repository at this point in the history
* 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
ryanh153 authored and pmayd committed Sep 24, 2019
1 parent fa6b78d commit acfa185
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions 01/ryanh153/README.md
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).
31 changes: 31 additions & 0 deletions 01/ryanh153/wordvalue.py
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

0 comments on commit acfa185

Please sign in to comment.