Skip to content

Conversation

@nnrepos
Copy link
Contributor

@nnrepos nnrepos commented Oct 5, 2022

Difficulty level (1-10): [1]
Estimated time spent (hours): [0.5]
Completed (yes/no): [yes]
I stretched my coding skills (if yes what did you learn?): [no]
Other feedback (what can we improve?): [probably makes more sense to use relative imports,
that way we don't have to copy and delete the files to run the tests.]

if dictionary is None:
dictionary = load_words()
print("crap:", [x for x in dictionary if "-" in x])
return list(sorted(([calc_word_value(word), word] for word in dictionary), reverse=True))[0][1]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorted() already returns a list. I would break this out into multiple lines, which would make it more readable.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using the max() built-in here, for example: https://github.com/pybites/challenges/blob/solutions/01/wordvalue.py

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was actually looking for something like this: key=calc_word_value. that's very nice

def calc_word_value(word: str) -> int:
"""Calculate the value of the word entered into function
using imported constant mapping LETTER_SCORES"""
return sum(LETTER_SCORES[letter] for letter in list(word.replace('-', '').upper()))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need the list(), word is already iterable. The solution also uses LETTER_SCORES.get(char.upper(), 0) which is safer, because with LETTER_SCORES[letter] any unexpected letter would raise a KeyError.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i actually used the KeyError for debugging (that's how i've discovered that - is a legal character), but for correctness, i guess you're right.

@bbelderbos bbelderbos merged commit 082efba into pybites:community Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants