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

Tigers: Sunny and Marie - Adagrams #65

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

Conversation

mkeefer17
Copy link

No description provided.

Copy link

@spitsfire spitsfire left a comment

Choose a reason for hiding this comment

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

Great job working together, Sunny and Marie!

Here are a few things to consider for future projects that I've detailed below in your code:

  • Some of the functions had for loops that iterated over the same lists twice. That's a great sign to combine the for loops, and maybe turn the conditional statements into compound conditional statements. NOTE: The exception to this rule might be when we are creating frequency maps, or building a data structure that will make iteration easier.

If you have any questions about the feedback, please reach out to me!

adagrams/game.py Outdated
@@ -1,11 +1,128 @@
from multiprocessing import current_process

Choose a reason for hiding this comment

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

oops looks like VSCode brought in an import line automatically. I don't see this used anywhere in your code, so let's take it out!

Suggested change
from multiprocessing import current_process

Choose a reason for hiding this comment

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

corrected

Comment on lines +47 to +49
for letter in LETTER_POOL:
for num in range(0,(LETTER_POOL[letter])):
letter_pool_list.append(letter)

Choose a reason for hiding this comment

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

Good idea here! This will allow for a better distribution of probability when picking letters randomly.

adagrams/game.py Outdated
Comment on lines 52 to 59
while len(my_ten_letters) < 10:
for num in range(0,10):
random_letter = random.choice(letter_pool_list)
my_ten_letters.append(random_letter)
my_string_count = my_ten_letters.count(random_letter)
word_pool_count = letter_pool_list.count(random_letter)
if my_string_count > word_pool_count:
my_ten_letters.remove(random_letter)

Choose a reason for hiding this comment

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

Hmm we are doing some extra work, only to remove it later. Let's refactor this. We know that we want this to run until our list my_ten_letters has 10 items. From here, we can simply remove the random_letter from our letter_pool_list list. Anything left in the letter_pool_list is an accurate representation of what can still be picked. No need to recount the letters that are left.

    while len(my_ten_letters) < 10:  
        random_letter = random.choice(letter_pool_list)  
        my_ten_letters.append(random_letter)  
        letter_pool_list.remove(random_letter) 

Choose a reason for hiding this comment

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

implemented ty!

adagrams/game.py Outdated
Comment on lines 68 to 71
if letter not in letter_bank:
letter_results.append("f")
if "f" in letter_results:
return False

Choose a reason for hiding this comment

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

If we hit this if statement on line 68, then we know immediately we should return False. No need to keep track of them in a new data structure. As soon as a letter in the word is not found in our hand, we return False.

I would recommend taking the return True out of the for loop, because if the for loop gets through the entire word, we know all letters are accounted for.

Choose a reason for hiding this comment

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

refactored

adagrams/game.py Outdated
Comment on lines 75 to 81
for letter in word:
count_pool_letter = letter_bank.count(letter)
count_word_letter = word.count(letter)
if count_word_letter > count_pool_letter:
return False
else:
return True

Choose a reason for hiding this comment

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

Nice check! Let's consider combining these two for loops together. We can check that the letter is in the letter_bank and that there are enough letters in the letter_bank to make the word.

Choose a reason for hiding this comment

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

refactored

adagrams/game.py Outdated
Comment on lines 87 to 88
if len(word) == 0:
return word_score

Choose a reason for hiding this comment

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

nice guard clause! let's put this at the toppy top, though.

Choose a reason for hiding this comment

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

implemented ty!

if count_word_letter > count_pool_letter:
return False
else:
return True

def score_word(word):

Choose a reason for hiding this comment

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

👍

adagrams/game.py Outdated
Comment on lines 111 to 113
if dict[1] == highest_score_value:
highest_scores.append(dict)

Choose a reason for hiding this comment

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

This works! But let's bring in the value as its own variable, so it is easier to understand what dict[1] is.

With the items method, we get access to both the key and value by doing: for key, value in dictionary.items()

So, we could say:

for word, score in score_dict.items():
    if score == highest_score_value:
    # the rest of your code here

Choose a reason for hiding this comment

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

implemented

adagrams/game.py Outdated
Comment on lines 118 to 126
for word, score in highest_scores:
if len(word) >= 10:
shortest_word = word
return (shortest_word, highest_score_value)
elif len(word) < shortest_word_length:
shortest_word_length = len(word)
shortest_word = word

Choose a reason for hiding this comment

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

Nice job! Could we do this all in one for loop? For example, find the score of a word, check if it's the highest score. Or if it's then equal to the highest score, we check if it's shorter or has a length of 10. If none of those are true, then the loop moves on to the next word.

Food for thought!

Choose a reason for hiding this comment

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

Noted

adagrams/game.py Outdated
'Y': 2,
'Z': 1
}
score_chart ={

Choose a reason for hiding this comment

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

Let's make this a constant, too. SCORE_CHART. Also stay consistent with your syntax. Your = should have a space before and after it.

Choose a reason for hiding this comment

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

implemented

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