Skip to content

C17 Otters - Natalya and Lin#38

Open
lin6692 wants to merge 8 commits intoada-c17:masterfrom
lin6692:master
Open

C17 Otters - Natalya and Lin#38
lin6692 wants to merge 8 commits intoada-c17:masterfrom
lin6692:master

Conversation

@lin6692
Copy link
Copy Markdown

@lin6692 lin6692 commented Mar 31, 2022

No description provided.

Copy link
Copy Markdown

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

Comment thread adagrams/game.py
del letter_pool_copy[letter]
else:
letter_pool_copy[letter] -= 1
drawn_letters.append(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.

Great solution!

Comment thread adagrams/game.py
for char in word:
if char not in letter_bank_copy:
return False
letter_bank_copy.remove(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.

💯

Comment thread adagrams/game.py
Comment on lines +83 to +85
for char, value in SCORE_CHART.items():
if letter in char:
score += value
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 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.

Comment thread adagrams/game.py
max_value = max(max_value, words_score[word])

# 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]
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!

Comment thread adagrams/game.py
# return the first word with the lenght 10 letters and it's score
# 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)
Copy link
Copy Markdown

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

Comment thread adagrams/game.py
for word in words_max_value:
if len(word) == 10:
return word, max_value
return words_max_value[0], max_value
Copy link
Copy Markdown

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