Open
Conversation
alope107
reviewed
Apr 7, 2022
alope107
left a comment
There was a problem hiding this comment.
Awesome job! This project is a verdant green. You've got some great compact code here. Nicely done~
| 'Y': 2, | ||
| 'Z': 1 | ||
| } | ||
| LETTER_POINTS = { |
Comment on lines
+63
to
+67
| while len(chosen_letters) < 10: | ||
| random_letter = random.choice(list(letter_pool)) | ||
| if letter_pool[random_letter] > 0: | ||
| chosen_letters.append(random_letter) | ||
| letter_pool[random_letter] -= 1 |
There was a problem hiding this comment.
Very clever! One small improvement: the call to list repeatedly transforms the keys of the dictionary into a list. By putting this outside the loop and assigning it to a variable we can reduce some duplicated effort.
Comment on lines
72
to
+80
| def uses_available_letters(word, letter_bank): | ||
| pass | ||
| letter_bank_copy = copy.deepcopy(letter_bank) | ||
| new_word = word.upper() | ||
| for letter in new_word: | ||
| if letter not in letter_bank_copy: | ||
| return False | ||
| else: | ||
| letter_bank_copy.remove(letter) | ||
| return True |
Comment on lines
83
to
+91
| def score_word(word): | ||
| pass | ||
| points = 0 | ||
| cased_word = word.upper() | ||
| if len(cased_word) >= 7: | ||
| points += 8 | ||
| for letter in cased_word: | ||
| points += LETTER_POINTS[letter] | ||
|
|
||
| return points |
Comment on lines
+100
to
+110
| for word in word_list: | ||
| if score_word(word) > champ_list[1]: | ||
| champ_list[0] = word | ||
| champ_list[1] = score_word(word) | ||
| elif score_word(word) == champ_list[1] and len(word) < len(champ_list[0]) and len(champ_list[0]) != 10: | ||
| champ_list[0] = word | ||
| champ_list[1] = score_word(word) | ||
| elif score_word(word) == champ_list[1] and len(word) == 10 and len(champ_list[0]) != 10: | ||
| champ_list[0] = word | ||
| champ_list[1] = score_word(word) | ||
| return champ_list |
There was a problem hiding this comment.
This works great! As an extra exercise, can you consider how you might write this differently by nesting some of your conditional blocks? Do you think this would make it more or less readable? There's no right answer here, it's subjective!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.