-
Notifications
You must be signed in to change notification settings - Fork 69
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
C17 Otters - Natalya and Lin #38
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work on this project Natalya and Lin! The code is very clean and readable. Nice work with your frequent commits! This project is green.
del letter_pool_copy[letter] | ||
else: | ||
letter_pool_copy[letter] -= 1 | ||
drawn_letters.append(letter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great solution!
for char in word: | ||
if char not in letter_bank_copy: | ||
return False | ||
letter_bank_copy.remove(char) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
for char, value in SCORE_CHART.items(): | ||
if letter in char: | ||
score += value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dictionary structure of SCORE_CHART is not optimal for this problem. The setup here with tuples as keys makes it necessary to search for the letter, but a dictionary where each letter is a key and the point value is the dictionary value would remove the need for this inner loop.
|
||
# Create a list of all words that have the highest score. | ||
words_max_value = [word for word, score in words_score.items() if score == max_value] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
# in all other cases return the first word in the list words_max_value as it has the fewest letters. | ||
if len(words_max_value) > 1: | ||
words_max_value = sorted(words_max_value, key=len) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works because the function sorted
is a stable sort function (https://docs.python.org/3/library/functions.html#sorted). From the linked doc:
The built-in sorted() function is guaranteed to be stable. A sort is stable if it guarantees not to change the relative order of elements that compare equal — this is helpful for sorting in multiple passes (for example, sort by department, then by salary grade).
if len(word) == 10: | ||
return word, max_value | ||
return words_max_value[0], max_value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great solution!
No description provided.