Skip to content

C22 - Brianna Root #28

Open
bri-root wants to merge 11 commits intoAda-C22:mainfrom
bri-root:main
Open

C22 - Brianna Root #28
bri-root wants to merge 11 commits intoAda-C22:mainfrom
bri-root:main

Conversation

@bri-root
Copy link

No description provided.

…ional in loop to count how many letters are in the letter bank, and used count to equal the number of letters in word
…eated a nested loop to read into the dictionary and lists to find the letter and then add the value to the score, which iterated through the word. Added the additioanl points if length of word is greater than 6.
… the score and word to variables outside of the loop.
output is a list of 10 random letters
"""
# assign variable names to the letters and max usage num
letter_list, usage_list = list(letter_pool.keys()), list(letter_pool.values())
Copy link

@mikellewade mikellewade Sep 20, 2024

Choose a reason for hiding this comment

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

Love the multi-assignment and your use of the dictionary methods here!

add_letter = hand.append(random_letter)
else:
continue
return hand

Choose a reason for hiding this comment

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

Right now your code isn't actually utilizing the weight distribution of the letters. Currently, all letters have the same chance of being selected (they all can only appear their respective limits). randint is only randomly selecting from a pool of integers from 0 to 26. This means that Z is just as likely as likely to be selected as E. You would need it to select from a pool of integers from 0 to 98 to have the correct distribution. How could we change your letter pool to consider this weighted distribution?

Comment on lines +59 to +67
# word = word.upper()
# count = 0
# for letter in word:
# if word.count(letter) > letter_bank.count(letter):
# return False
# elif letter in letter_bank:
# count += 1
# if count == len(word):
# return True
Copy link

@mikellewade mikellewade Sep 20, 2024

Choose a reason for hiding this comment

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

Don't forget to remove your comments like these.

# if count == len(word):
# return True

word = word.upper()
Copy link

@mikellewade mikellewade Sep 20, 2024

Choose a reason for hiding this comment

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

Nice work on ensuring that all the letters where of the same casing. You could also use casefold, which is used for caseless matching. You can find more information on the method here.

Also, be mindful of re-assigning the parameter of a function. That could cause issues for the caller of the function if the change is not expected. Usually we want to avoid this unless specifically told to.


for each_letter in word:
if each_letter in letter_bank_copy:
list.append(each_letter)

Choose a reason for hiding this comment

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

Right now I don't see the use case for making the list and appending things to it. If you remove it from your code it would work the same. Feel free to reply to this comment and explain your reasoning.

letter_bank_copy.remove(each_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.

An Alternative approach to this function could be:

def uses_available_letters(word, letter_bank):
    casefold_word = word.casefold()
    temporary_letter_bank =  [letter.casefold() for letter in letter_bank]

    for letter in casefold_word: 

        if letter not in temporary_letter_bank:  
            return False

        temporary_letter_bank.remove(letter) 

    return True

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

return score

Choose a reason for hiding this comment

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

Very concise and readable! ⭐️

# if the lenth of word is 10, chooses it or the first word
if each_value == 10:
highest_value_word = each_key
break

Choose a reason for hiding this comment

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

🎉

word_length = each_value
highest_value_word = each_key

return highest_value_word, highest_value No newline at end of file

Choose a reason for hiding this comment

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

Nice work writing this function. The separation of the getting the tying score words and the tie-breaking logic help this to be more readable here (especially if you ever have to debug it). An alternative approach could be like this:

def get_highest_word_score(word_list):
    best_word = ""
    best_score = 0 
    
    for word in word_list:
        score = score_word(word)

        if score > best_score:
            best_word = word
            best_score = score

        elif score < best_score:
            pass

        elif len(best_word) == 10:
           break

        elif len(word) == 10 or len(word) < len(best_word):
            best_word = word
            best_score = score

    return (best_word, best_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