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

C17 Otters - Natalya and Lin #38

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

Conversation

lin6692
Copy link

@lin6692 lin6692 commented Mar 31, 2022

No description provided.

Copy link

@jbieniosek jbieniosek left a 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)

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)

Choose a reason for hiding this comment

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

💯

Comment on lines +83 to +85
for char, value in SCORE_CHART.items():
if letter in char:
score += value

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]

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)

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

Choose a reason for hiding this comment

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

Great solution!

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