Conversation
jbieniosek
left a comment
There was a problem hiding this comment.
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) |
| for char in word: | ||
| if char not in letter_bank_copy: | ||
| return False | ||
| letter_bank_copy.remove(char) |
| for char, value in SCORE_CHART.items(): | ||
| if letter in char: | ||
| score += value |
There was a problem hiding this comment.
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.
| 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] |
| # 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) |
There was a problem hiding this comment.
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).
| for word in words_max_value: | ||
| if len(word) == 10: | ||
| return word, max_value | ||
| return words_max_value[0], max_value |
No description provided.