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

Cohort_22_Phoenix_Marjana_Khatun #47

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

Conversation

marjanak
Copy link

No description provided.

Copy link
Collaborator

@kelsey-steven-ada kelsey-steven-ada 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 Marjana! Let me know if you have questions on any of the feedback =]

}


list_letters = []
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a duplicate of the variable we declare on line 4, so one of them should be removed.

def draw_letters():
pass
list_letters = []
distribution_of_letters = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice placement of the distribution_of_letters structure in the function. It's a tradeoff of visually taking up space in the function so we don't need to worry about changes to the structure between function calls.

Comment on lines +36 to +42
while len(list_letters) != 10:
letters = list(distribution_of_letters.keys())
random_letter = random.choice(letters)
value = distribution_of_letters[random_letter]
if value > 0:
distribution_of_letters[random_letter] = value -1
list_letters.append(random_letter)
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is a subtle issue with how we're selecting tiles. We are guaranteed to always get a hand of 10, and we are picking from the full alphabet and ensuring we aren't picking too many of a certain tile however, we aren't taking into account the correct probability of grabbing a particular tile.

When we grab a tile, we are picking from the keys of distribution_of_letters. This means we have an equal 1 in 26 chance to grab any letter. However, based on our distributions, we should have many more of some tiles than others, which means we should be more likely to pick those tiles than others.

We can get around this a number of ways; one possibility is creating a list containing all of our possible tiles, then remove each tile from this list as we randomly select them.

list_letters = []
while len(list_letters) != 10:
letters = list(distribution_of_letters.keys())
random_letter = random.choice(letters)
Copy link
Collaborator

Choose a reason for hiding this comment

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

In this cohort we shared guidance during Unit 1 asking folks to stick to using randint and avoid functions from the random package that do more of the random selection work like sample and choice. How would your implementation change using only random.randint?

Comment on lines +51 to +52
else:
return False
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice early exit as soon as we find a letter that isn't in the letter_bank!

Comment on lines +48 to +50
for letter in word:
if letter in letters_copy:
letters_copy.remove(letter)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a clear and concise solution, but what is the time complexity like? For each letter in word we may need to make a full loop over letters_copy. If letter exists in letters_copy, the remove method is O(n) in the worst case where we remove the first element and need to shift all elements down.

How could we use frequency maps to reduce our time complexity?

total_score = 0
word = word.upper()
for letter in word:
value = score.get(letter, 0)
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 get to handle non-letter characters like hyphens!

"Z" :10
}
total_score = 0
word = 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.

In this case it isn't a big deal, but we typically don't want to overwrite our parameter variables since we lose access to the original value.

Comment on lines +105 to +109
highest_word = word
elif len(word)<len(highest_word):
highest_word = word
return(highest_word,highest_score)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Reminder about spacing around operators and commas to make statements easier to read quickly.

Suggested change
elif len(word)== 10:
highest_word = word
elif len(word)<len(highest_word):
highest_word = word
return(highest_word,highest_score)
elif len(word) == 10:
highest_word = word
elif len(word) < len(highest_word):
highest_word = word
return(highest_word, highest_score)

Comment on lines +103 to +108
continue
elif len(word)== 10:
highest_word = word
elif len(word)<len(highest_word):
highest_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.

We don't take an action inside the if statement and both sides of the elif blocks have the same contents highest_word = word. Repeating code like this is often a sign that we should look at our code to see if there are ways we could combine our statements to reduce repetition.

Thinking about long-term code maintenance, if we have to change that code in the future, it goes quicker and is less error-prone when there is only one line to update, rather than several lines that we need to keep in sync.

One of many options could be to create variables for the boolean statements:

is_new_word_ten = len(word) == 10 and len(highest_word) != 10
is_new_word_smaller = len(word) < len(highest_word) and len(highest_word) != 10
if is_new_word_ten or is_new_word_smaller:
    highest_word = word

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