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

Spruce - Mary Tian #52

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open

Spruce - Mary Tian #52

wants to merge 19 commits into from

Conversation

Mary-Tian
Copy link

No description provided.

Copy link
Collaborator

@audreyandoy audreyandoy 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 Mary and Rebecca!

Your submission covers all the learning goals and passes all the tests! Overall, the code was clean and easy to read. This project is definitely worthy of a green grade 🟢 🌲✨

My feedback primarily focuses on ways to use guard clauses, using const variables, and syntax for iterating through dictionaries. I also loved all the docstrings under each function, they were definitely helpful in understanding your thought process for these solutions.

Keep up the great work 🌲 ✨

Comment on lines +10 to +14
LETTER_POOL = {
'A': 9, 'B': 2, 'C': 2, 'D': 4, 'E': 12, 'F': 2, 'G': 3, 'H': 2, 'I': 9, 'J': 1,
'K': 1, 'L': 4, 'M': 2, 'N': 6, 'O': 8, 'P': 2, 'Q': 1, 'R': 6, 'S': 4, 'T': 6, 'U': 4,
'V': 2, 'W': 2, 'X': 1, 'Y': 2, 'Z': 1
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Long chunks of data like letter_bank tend to clutter functions and require more scrolling to see the rest of the function body. Consider moving this dictionary outside of this function (or in a new file) as a constant variable to be referenced in draw_letters.

'K': 1, 'L': 4, 'M': 2, 'N': 6, 'O': 8, 'P': 2, 'Q': 1, 'R': 6, 'S': 4, 'T': 6, 'U': 4,
'V': 2, 'W': 2, 'X': 1, 'Y': 2, 'Z': 1
}
letter_to_draw = list(LETTER_POOL.keys())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
letter_to_draw = list(LETTER_POOL.keys())
letter_to_draw = list(LETTER_POOL)

We can omit keys() as the default iterator for dictionaries are its own keys. This means the list function will iterate through LETTER_POOL and create a list of its keys.

Comment on lines +18 to +24
for letter in random.sample(letter_to_draw, 10):
if letter not in letters_drawn:
letters_drawn.append(letter)
letter_count[letter] = 1
elif letter_count[letter] < LETTER_POOL[letter]:
letters_drawn.append(letter)
letter_count[letter] += 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

Love the use of a frequency map to keep track of the letters being drawn!

Copy link
Collaborator

Choose a reason for hiding this comment

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

We could also use sample to build letters_drawn directly from LETTER_POOL.

    letters_drawn = random.sample(LETTER_POOL.keys(), counts=LETTER_POOL.values(), k=10)

Here's the sample documentation, if you'd like to learn more about the method.

Comment on lines +35 to +41
for letter in word:
if letter not in letter_bank or word.count(letter) > letter_bank.count(letter):
is_valid = False
else:
is_valid = True

return is_valid
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great use of a guard clause here. We can make the code even neater by getting rid of the else clause (aka the dangly bit). To do so, we can take advantage of using the is_valid flag to describe the single scenario where is_valid would be false in the guard clause. Otherwise, the function will just return True. Like so:

    is_valid  = True 
    for letter in word:
        if letter not in letter_bank or word.count(letter) > letter_bank.count(letter):
            is_valid = False

    return is_valid
Suggested change
for letter in word:
if letter not in letter_bank or word.count(letter) > letter_bank.count(letter):
is_valid = False
else:
is_valid = True
return is_valid
is_valid = True
for letter in word:
if letter not in letter_bank or word.count(letter) > letter_bank.count(letter):
is_valid = False
return is_valid

Comment on lines +49 to +53
LETTER_POINTS = {
'A': 1, 'B': 3, 'C': 3, 'D': 2, 'E': 1, 'F': 4, 'G': 2, 'H': 4, 'I': 1, 'J': 8,
'K': 5, 'L': 1, 'M': 3, 'N': 1, 'O': 1, 'P': 3, 'Q': 10, 'R': 1, 'S': 1, 'T': 1, 'U': 1,
'V': 4, 'W': 4, 'X': 8, 'Y': 4, 'Z': 10
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar to my feedback on LETTER_POOL, we can declutter this function by moving LETTER_POINTS outside of the function as a const variable.

'V': 4, 'W': 4, 'X': 8, 'Y': 4, 'Z': 10
}
bonus_range = [7, 8, 9, 10]
total = sum([LETTER_POINTS[letter] for letter in word.upper()])
Copy link
Collaborator

Choose a reason for hiding this comment

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

LOVELY use of list comprehension here!

if len(word) in bonus_range:
total += 8

return total
Copy link
Collaborator

Choose a reason for hiding this comment

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

This function is so neat, great work!

Comment on lines +71 to +72
largest_word_len = max((len(key) for key in words_scored_dict.keys()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

keys() can be removed as the default iterator for dicts are its own keys.

Suggested change
smallest_word_len = min((len(key) for key in words_scored_dict.keys()))
largest_word_len = max((len(key) for key in words_scored_dict.keys()))
smallest_word_len = min((len(key) for key in words_scored_dict.keys()))
largest_word_len = max((len(key) for key in words_scored_dict.keys()))

Copy link
Collaborator

Choose a reason for hiding this comment

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

Really cool use of dictionary and list comprehensions!!

Comment on lines +76 to +81
continue
elif len(user_word) == 10:
winning_word = user_word
highest_word_score = score
break
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can take out if len(user_word) != 10 as the loop will continue anyway.

Suggested change
if len(user_word) != 10:
continue
elif len(user_word) == 10:
winning_word = user_word
highest_word_score = score
break
if len(user_word) == 10:
winning_word = user_word
highest_word_score = score
break

winning_word = user_word

return winning_word, highest_word_score
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great work!

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