Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pcc01 #861

Open
wants to merge 5 commits into
base: community
Choose a base branch
from
Open

Pcc01 #861

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions 01/ananda23-cs/wordvalue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from data import DICTIONARY, LETTER_SCORES

def load_words():
"""Load dictionary into a list and return list"""
with open(DICTIONARY) as f:
return 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