Skip to content

Commit

Permalink
First submission (pybites#324)
Browse files Browse the repository at this point in the history
* add .vscode/ to .gitignore

* complete PCC01
  • Loading branch information
hishamo76 authored and pybites committed Oct 1, 2018
1 parent 88c8ae0 commit d561253
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
**sqlite
.idea/
.DS_Store
.vscode
25 changes: 25 additions & 0 deletions 01/hishamo76/wordvalue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from data import DICTIONARY, LETTER_SCORES


def load_words():
"""Load dictionary into a list and return list"""
with open(DICTIONARY) as f:
return [word.strip() for word in f.read().split()]


def calc_word_value(word):
"""Calculate the value of the word entered into function
using imported constant mapping LETTER_SCORES"""
return sum(LETTER_SCORES.get(char.upper(), 0) for char in word)


def max_word_value(words=None):
"""Calculate the word with the max value, can receive a list
of words as arg, if none provided uses default DICTIONARY"""
if words is None:
words = load_words()
return max(words, key=calc_word_value)


if __name__ == "__main__":
pass # run unittests to validate

0 comments on commit d561253

Please sign in to comment.