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

C16 - Spruce - Sandra Caballero and Vange Spracklin #46

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

Conversation

HouseOfVange
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 Sandra and Vange!

Your submission covers all the learning goals and passes all the tests! This project is definitely worthy of a green grade 🟢 🌲✨

My feedback primarily focuses on ways to use guard clauses, methods from the random package, and compound conditional expressions. Overall, the code was clean and easy to read.

Keep up the great work 🌲 ✨

@@ -1,11 +1,199 @@
import random

LETTER_POOL = (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great choice in using a tuple of nested dictionaries. While we encourage copying any data structure rather than altering it directly, the tuple adds an extra layer of protection.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I also like how the tuple is stored as a constant variable to prevent clogging up other functions. Keeping the functions nice and focused!

}
}
)

def draw_letters():
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Comment on lines +146 to +150
for i in range(10):
index = random.randint(0, len(letter_pool_list)-1)
letter = letter_pool_list[index]
hand_of_letters.append(letter)
letter_pool_list.pop(index)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good use of pop to ensure that a letter isn't selected more than it's frequency.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Optionally, random.sample() can be used here to generate the random letters instead of this for loop.

Suggested change
for i in range(10):
index = random.randint(0, len(letter_pool_list)-1)
letter = letter_pool_list[index]
hand_of_letters.append(letter)
letter_pool_list.pop(index)
hand_of_letters = random.sample(letter_pool_list, 10)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Here's more info on the sample in case it will come handy in the future: https://docs.python.org/3/library/random.html#random.sample


def uses_available_letters(word, letter_bank):
pass
letter_bank_copy = letter_bank[:]
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 the slice operator to make a shallow copy.

Comment on lines +158 to +163
for letter in word_character_list:
if letter in letter_bank_copy:
letter_bank_copy.remove(letter)
else:
return False
return True
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 restructure this block by reversing the conditional logic into a guard clause. The if letter not in letter_bank_copy will become the 'guard' that checks if letter does not meet the criteria to make the loop continue. In this case, if letter is not in letter_bank_copy list then the loop will exit early and return False.

As Ansel describes, the guard clause removes the need for dangly bits like the else clause.

Suggested change
for letter in word_character_list:
if letter in letter_bank_copy:
letter_bank_copy.remove(letter)
else:
return False
return True
for letter in word_character_list:
if letter not in letter_bank_copy:
return False
letter_bank_copy.remove(letter)
return True

letter_bank_copy.remove(letter)
else:
return False
return True

def score_word(word):
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Comment on lines +190 to +193
continue
elif len(top_word) == 10:
continue
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 combine these two into a combined conditional expressions since they contain the same logic:

Suggested change
if len(word) == 10 and len(top_word) == 10:
continue
elif len(top_word) == 10:
continue
if len(word) == 10 and len(top_word) == 10 or len(top_word) == 10:
continue

top_score = score_word(word)

best_word = [top_word, top_score]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Our tests don't check for the return type, but the word and the score should be returned as a tuple rather than a list. Tuples, like lists, also use indexing to access values which is why your solution passed the tests.

Suggested change
best_word = [top_word, top_score]
return word_result, score_count

or

Suggested change
best_word = [top_word, top_score]
best_word = (top_word, top_score)

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