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

Amethyst Megan G. #20

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

Amethyst Megan G. #20

wants to merge 2 commits into from

Conversation

scrambledmegs
Copy link

No description provided.


# helper function to create one big list of strings

def get_one_list_of_letters():

Choose a reason for hiding this comment

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

Yessss! I love how you are making use of helper functions here! It allows how us make more concise and readable code! Also great job on leaving a comment about what this function does.

def get_one_list_of_letters():

total_letters_list = []
for elem in LETTER_POOL:

Choose a reason for hiding this comment

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

I really like how you created a nested data structure and then you used a nested loop to build a big list for you to pull a random letter from. You definitely are showing proficiency when it comes to this topic! ⭐️

i = 0
while i < 10:
# randomize letter choice
random_letter = total_letters_list[random.randint(0, 97)]

Choose a reason for hiding this comment

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

Small comment, one thing that we want to try to avoid as developers is hard coding values inside for code base. So, instead using 97, we could maybe do len(total_letters_list) that way if anyone wants to change the weights of the letter then they won't have change the 97 as well! Again, just a small change to make your code more scalable.

Comment on lines +57 to +62
if hand.count(random_letter) < total_letters_list.count(random_letter):
hand.append(random_letter)
else:
# use continue to end this iteration and immediately start next iteration
continue
i += 1

Choose a reason for hiding this comment

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

count is a great function to use in a situation like this! That way you don't have worry about manipulating any data and removing things! An alternative refactor we could do to make the code a bit more concise is this:

while len(hand) < 10:
     random_letter = total_letters_list[random.randint(0, 97)]

     if hand.count(random_letter) < total_letters_list.count(random_letter):
            hand.append(random_letter)

This code will run the same as yours, this code just doesn't keep track of a counter since the times we append to hand is equal to len(hand)

Comment on lines 66 to +80
def uses_available_letters(word, letter_bank):
pass

# made copy of list as to not modify the original copy
letter_bank_copy = copy.deepcopy(letter_bank)

# iterate through each letter in the word and make letters all uppercase
for letter in word.upper():

if letter in letter_bank_copy:
# remove letter from letter bank so it can't be reused
letter_bank_copy.remove(letter)
else:
return False

return True

Choose a reason for hiding this comment

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

Nice use of the deepcopy function here, it lets you get a copy of the letter_bank without changing the object itself. This shows me that you have a good understanding of variables and memory. An alternative approach that doesn't mutate the original letter_bank is this here:

def uses_available_letters(word, letter_bank):
    cap_word = word.upper()
    for letter in cap_word:
       if letter_bank.count(letter) == 0: 
          return False

       if cap_word.count(letter) > letter_bank.count(letter):
          return False
    
    return True

It is basically the same thing as what you had in wave 1, using the count function to count the instances of a letter in both the word and letter_bank.

Comment on lines +98 to +99
for key in letter_values:
if letter in key:

Choose a reason for hiding this comment

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

Awesome, Megan! You used tuples as the keys for your dictionary and then used the if letter in key to add up the score! ⭐️

if len(word) > 6:
score += 8

return score

def get_highest_word_score(word_list):

Choose a reason for hiding this comment

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

Great function! I know we talked about this logic in co-working and you implemented very well! 🤩

winning_word = word

return winning_word, highest_score

Choose a reason for hiding this comment

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

Megan, you completed your first official Ada project! Congrats! Your code was a pleasure to look through! Very easy to follow and quite concise! Please feel free to reach out if you need any clarifications on the comments I left! You did great! Can't wait to review more of your code! 😝✨

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