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

Panthers - Jamaica A. #73

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

Conversation

jamaicayancy
Copy link

No description provided.

@sikasarpong
Copy link

Deleted play_test.py in adagrams folder to match Ada-C18:master and prevent errors when running test for url link in Learn/galvanize

Copy link

@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.

Congrats on completing your first pair project Jamaica & Sika! I’ve added some suggestions & questions, let me know if there's anything I can clarify 😊




score_chart = {

Choose a reason for hiding this comment

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

Placed out here as a global constant, I would recommend using all caps naming: SCORE_CHART.

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

LETTER_POOL = {

Choose a reason for hiding this comment

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

Since LETTER_POOL and score_chart are each accessed by one function, it would be reasonable to place them inside the functions rather than as a constant. There are tradeoffs, the structures would clutter the function some, but it keeps the data as close as possible to where it's being used, and would mean other functions couldn't access it to accidentally alter the contents.

Comment on lines +69 to +70
while len(new_list) <10:
letter = (random.choices(list(LETTER_POOL.keys()), weights = list(LETTER_POOL.values()), k=1))[0]

Choose a reason for hiding this comment

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

Nice use of random.choices!

This line gets pretty long, to keep it under the PEP8 recommendation of 79 characters we should split it up over a couple lines. Something we could do that would also lighten the processing we do each iteration could be pulling the list creations out of this line and storing them in variables above the loop.

    letters_list = list(LETTER_POOL.keys())
    letter_weights = list(LETTER_POOL.values())

    while len(new_list) <10:
        letter = random.choices(letters_list, weights = letter_weights, k = 1)[0]

if new_list.count(letter) < LETTER_POOL[letter]:
new_list.append(letter)

return(new_list)

Choose a reason for hiding this comment

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

We want to be consistent in how we do things across a project and remove syntax we don't need. I'd recommend always placing a space between the return keyword and the content that follows, and removing surrounding parentheses unless they are required to separate multiple expressions.

Comment on lines +79 to +81
letter_bank_copy = letter_bank.copy()
if len(word) > len(letter_bank_copy):
return False

Choose a reason for hiding this comment

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

Nice quick check to rule out words with an invalid length!

This implementation will allocate space for letter_bank_copy before we know if the input word is too long to be valid. If line 80 checked against the length of the input letter_bank, then we could move the if statement to the top of the function, and only create the deep copy if we know we need it.

    if len(word) > len(letter_bank):
        return False

    letter_bank_copy = letter_bank.copy()

Comment on lines +131 to +133

return(winner, winner_score)

Choose a reason for hiding this comment

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

The variable top_score is already holding the max score for our tied words. This means we could remove line 131 and use top_score on line 133:

    return(winner, top_score)


if len(winner_list) == 1:
winner = (winner_list[0])

Choose a reason for hiding this comment

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

Great thought to check the length of winner_list to see if we can exit early!

Comment on lines +124 to +125
winner2 = min(winner_list, key=len)

Choose a reason for hiding this comment

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

winner1 and winner2 as names don't tell us much about the difference between these variables. I would consider using names that give the reader more information. One of many possibilities could be longest_winner & shortest_winner.

Comment on lines +126 to +129
winner = winner1
else:
winner = winner2

Choose a reason for hiding this comment

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

Really nice use of min and max to tiebreak on length!

winner = (winner_list[0])

if len(winner_list) > 1:

Choose a reason for hiding this comment

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

Since we know we will never need to enter the if here on line 123 if we entered if len(winner_list) == 1: on line 120, I would consider using an elif here. With an elif, if we hit line 120 and enter if len(winner_list) == 1:, then the code knows we entered the if-statement and will not bother evaluating the following connected elif statements, saving us the tiniest bit of processing.

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