Skip to content

Kunzite - Danica S#124

Open
dsarm-edu wants to merge 4 commits into
Ada-C19:mainfrom
dsarm-edu:main
Open

Kunzite - Danica S#124
dsarm-edu wants to merge 4 commits into
Ada-C19:mainfrom
dsarm-edu:main

Conversation

@dsarm-edu

Copy link
Copy Markdown

No description provided.

@anselrognlie anselrognlie left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice job! 🎉 Your tests are all passing and your code is well-organized. The main thing I'd encourage is to include comments about your understanding of any library functions being called (or even give a whirl writing them yourself as you did with the code for min). Sometimes, library functions, while helpful, may conceal hidden costs that we may be able to work around ourselves, as we'll learn more about shortly. Implementing the logic ourselves can help us become aware of that.

Also, take a look at the tie breaking logic in get_highest_word_score, as it looks like we could end up picking a 10-letter word too quickly.

Overall, well done!

Comment thread adagrams/game.py
pass
big_list = []
for letter, letter_quantity in LETTER_POOL.items():
big_dict = letter * letter_quantity

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice use of repetition to handle including multiple cpoies of a letter. Since your objective was to eventually add this to a list, consider

        letters = [letter] * letter_quantity

which will make a list rather than a string. This can then be added to your growing list as

    big_list.extend(letters)
    # or
    big_list += letters

Comment thread adagrams/game.py
big_dict = letter * letter_quantity
for single_char in big_dict:
big_list.append(single_char)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider moving the first part of this function to a helper function that builds an expanded list from a dictionary of keys with counts.

Comment thread adagrams/game.py
big_list.append(single_char)

draw_of_10_letters = []
while len(draw_of_10_letters) < 10:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider using a for loop. Since you built an explanded list, you know every pick will be "successful". So we know this will loop exactly 10 times.

Comment thread adagrams/game.py

draw_of_10_letters = []
while len(draw_of_10_letters) < 10:
random_letter = random.choice(big_list)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

When using a library function like this that we haven't discussed, I encourage you to either include a comment that explains your understanding of how it works, or consider implementing the logic yourself rather than using the library function for additional practice!

Comment thread adagrams/game.py
while len(draw_of_10_letters) < 10:
random_letter = random.choice(big_list)
draw_of_10_letters.append(random_letter)
big_list.remove(random_letter)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

As we start to discuss big O (coming up) we'll see that removing from a list is realtivelty inefficient. This does guarantee that future picks won't use a letter we've already "consumed", but in a loop, we'd like to avoid remove if possible.

Comment thread adagrams/game.py
else:
total_score += score_chart[letter]
if 7 <= len(word) <= 10:
total_score += 8

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Nice bonus handling.

Comment thread adagrams/game.py
Comment on lines +94 to +95
if len(word) == 10:
return ((word, score))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since the best_words_list hasn't been filtered by score (and words can appear in any order), we can't say for certain that the first 10 letter word we find is the winner. There might be a higher scoring 10-letter word later in the list.

If we filtered the list so that the only words in it are those with the highest score, then this assumption would be accurate.

Comment thread adagrams/game.py
for word, score in best_words_list:
if len(word) == 10:
return ((word, score))
else:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The else here isn't needed. Since the loop will either complete without exiting (triggering the else) or return from the function (in which case, there's no risk of running the code following the loop), we know that if we reach the code after the loop, it can only be due to the look exiting normally (there's no break).

As such, we can remove the else and unindent the remaining code.

Comment thread adagrams/game.py
else:
top_score = 0
best_word = []
for word, score in best_words_list:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍 Nice tuple unpacking during the iteration.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice way to get the list of words tied for the best score. Consider doing this logic when building the best_words_list (which would address the 10-letter word check).

Comment thread adagrams/game.py
Comment on lines +107 to +109
for word in best_word:
if len(short_word) > len(word):
short_word = word

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice job finding the shortest word from among the words tied for the best score.

From the commented code below, it looks like you were also looking into max/min as wyas to accomplish some of this. Now that you've implemented the logic behind min yourself, I'd definitely suggest incoroporating min/max in future 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