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

C19 Sapphire - Linh Huynh #116

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open

C19 Sapphire - Linh Huynh #116

wants to merge 20 commits into from

Conversation

mlhuynh
Copy link

@mlhuynh mlhuynh commented Mar 24, 2023

No description provided.

…y as individual elements within an empty list for easier selection later down the line.
…en a letter in the selected word is not present in the available collection (or hand) of letters.
…where user overuses a letter beyond the available amount.
…l points for inputted words. Sorry, I need to learn how to write more succinct git notes.
…y in a cleaner, more succinct manner by getting rid of unnecessary for loop iterations and eliminating the need of a SCORE_CHART_LOWERCASE dictionary.
…d with fewest letters in the event of a tie.
…tied score (for both scenarios where the winning word should have the fewest letters or 10 letters).
Copy link

@tildeee tildeee left a comment

Choose a reason for hiding this comment

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

Great work on this project, Linh!

Overall, your project shows clear practice of iteration. I think it was really great how you thought about and used word_verification. However, I think there are places where the solution could be more efficient if you chose different ways to keep data. I'm seeing a lot of lists being used to hold a lot of things, when a boolean, another variable, or something else would do. I think it might be helpful to revisit this project and think about ways to simplify what you already have.

In addition, I'd like to encourage you to practice keeping your variables as local as possible, as a best practice around variable scope. Also, it makes for cleaner code style!

Lastly, I'd like to say that your git hygiene is great-- thank you for the messages that start with verbs and tell me clearly what the code change is. Please keep that up! :D

A test failure means that I'm marking this project as "yellow," as a sign to check-in about the feedback. This is my first time getting to know your code, and I know I'm a new reviewer. Please let me know what questions or comments you have, here or through Slack, any time!

import random
from collections import Counter

LETTER_POOL = {
Copy link

Choose a reason for hiding this comment

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

Great call making these constants

Comment on lines +62 to -2
LETTER_POOL_LIST = []
temp_list = []

def draw_letters():
pass
Copy link

Choose a reason for hiding this comment

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

Your solution would benefit if we moved these two variables to inside the draw_letters function, so instead:

def draw_letters():
    LETTER_POOL_LIST = []
    temp_list = []
    # ...

The first sign that we should move these variables is because they are only used/modified/accessed within one function: the draw_letters function. We want our variables to have the smallest scope as possible-- so if other functions don't need access to LETTER_POOL_LIST and temp_list, then let's make them local variables.

As a note, if we move these variables, all of your tests pass! Please let me know if you'd like to talk together about why this fix works.

Comment on lines +71 to +72
for sublist in temp_list:
for letter in sublist:
Copy link

Choose a reason for hiding this comment

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

For me, it's hard to understand what sublist represents by its name. I would suggest renaming sublist to letter_list or something else more specific, and if you're having trouble coming up with a name, to revisit what it's used for


return hand

draw_letters()
Copy link

Choose a reason for hiding this comment

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

This line doesn't do anything meaningful right now, since it's not in a test file or a function! This line is safe to delete.

Comment on lines +96 to +102
for letter in letter_bank:
if letter not in hand_letter_count:
count = 1
hand_letter_count[letter] = count
else:
count += 1
hand_letter_count[letter] = count
Copy link

Choose a reason for hiding this comment

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

Your logic is sound here, but there are a couple of ways we can make it clearer by focusing on count. Firstly, count is only used in one place: inside this single for loop. Therefore, we could move the definition of count:

    for letter in letter_bank:
        count = 0
        if letter not in hand_letter_count:
            count = 1
            hand_letter_count[letter] = count
        else: 
            count += 1
            hand_letter_count[letter] = count

Afterwards, we can really see how count is being used. We could even find a way to refactor it out and avoid it:

    for letter in letter_bank:
        if letter not in hand_letter_count:
            hand_letter_count[letter] = 1
        else: 
            hand_letter_count[letter] += 1

This code has the exact same logic as your original project, and three less lines and one less variable!

Comment on lines +122 to +123
if word == "":
word_score["empty"] = 0
Copy link

Choose a reason for hiding this comment

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

This code says to me "if word is empty, then the total score is 0". I think that adding "empty" into word_score isn't as straightforward as we can be, although I see that you're trying to give the score 0 even if the word has a length of 0 (an empty string). An alternative solution is to return 0 inside this conditional:

    if word == "":
      return 0

Comment on lines +120 to +135
word_score = {}

if word == "":
word_score["empty"] = 0

for letter in word.upper():
if letter in SCORE_CHART:
if letter not in word_score:
word_score[letter] = SCORE_CHART[letter]
else:
word_score[letter] += SCORE_CHART[letter]

if 7 <= len(word) <= 10:
word_score["bonus"] = 8

return sum(word_score.values())
Copy link

Choose a reason for hiding this comment

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

I think your approach to this problem is interesting and extensible-- I think that adding "bonus" key and summing word_score.values() is really smart for an expanded project. In this situation, if you wanted to refactor and make word_score an integer, instead of a {}, then that would also pass the tests.

Comment on lines +153 to +157

for word, score in score_dict.items():
if score in matching_scores:
matching_scores_dict[word] = score
Copy link

Choose a reason for hiding this comment

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

From what I can tell, this code is finding all times that there is a non-unique score, and collects them in a dictionary between word and score. However, do we need to keep a dictionary of matching scores to find the best word?

matching_scores_dict[word] = score

for word, score in matching_scores_dict.items():
Copy link

Choose a reason for hiding this comment

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

Instead of iterating through matching_scores.dict.items(), what if we iterate through score_dict instead? score_dict is a dictionary that already keeps each word and its score. We already have a value for highest_score and winning_word, too!

If we refactor this loop so it iterates through score_dict, we can also delete the code around matching scores. If we make these changes, then the tests still pass!

@@ -38,6 +38,7 @@ def test_draw_letters_draws_ten():
# Assert
assert len(letters) == 10

#@pytest.mark.skip(reason="no way of currently testing this")
Copy link

Choose a reason for hiding this comment

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

Would be good to delete these lines in a commit

@mlhuynh
Copy link
Author

mlhuynh commented Apr 3, 2023 via email

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.

3 participants