Conversation
|
|
||
| import random | ||
|
|
||
| main_letters_list = ["a", "a", "a", "a", "a", "a", "a", "a","a", "b", "b", "c", "c", "d", "d", "d", "d", "e", "e", "e", "e", "e", "e", "e", "e", "e", "e", "e", "e", "f", "f", "g", "g", "g", "h", "h", "i", "i", "i", "i", "i", "i", "i", "i", "i", "j", "k", "l", "l", "l", "l", "m", "m", "n", "n", "n", "n", "n", "n", "o", "o", "o", "o", "o", "o", "o", "o", "p", "p", "q", "r", "r", "r", "r", "r", "r", "s", "s", "s", "s", "t", "t", "t", "t", "t", "t", "u", "u", "u", "u", "v", "v", "w", "w", "x", "y", "y", "z"] |
There was a problem hiding this comment.
I would suggest making this a global constant variable to remove "clutter" from your function
| main_letters_list_copy = [] | ||
| user_hand = [] | ||
|
|
||
| for letter in main_letters_list: | ||
| main_letters_list_copy.append(letter) |
There was a problem hiding this comment.
I would look into the copy() and deepcopy() methods that could be used here to save you some lines of code: https://docs.python.org/3/library/copy.html
| letter_bank_copy = [] | ||
| for letter in letter_bank: | ||
| letter_bank_copy.append(letter) |
There was a problem hiding this comment.
same suggestion about using copy() method. Even though this works great!
| score_chart = { | ||
| 1: ["A", "E", "I", "O", "U", "L", "N", "R", "S", "T"], | ||
| 2: ["D", "G"], | ||
| 3: [ "B", "C", "M", "P"], | ||
| 4: ["F", "H", "V", "W", "Y"], | ||
| 5: ["K"], | ||
| 8 : ["J", "X"], | ||
| 10: [ "Q", "Z"] | ||
| } |
There was a problem hiding this comment.
loved how you set up the key-value pairs. I would suggest making this a global constant variable.
| highest_score_word_list = [] | ||
| comparing_word_scores = {} | ||
| current_word_score = 0 | ||
| for word in word_list: | ||
| current_word_score = score_word(word) | ||
| if comparing_word_scores.get(current_word_score): | ||
| comparing_word_scores[current_word_score].append(word) | ||
| else: | ||
| comparing_word_scores[current_word_score] = [] | ||
| comparing_word_scores[current_word_score].append(word) | ||
|
|
||
| current_highest_score=0 | ||
| for score, words in comparing_word_scores.items(): | ||
| if score > current_highest_score: | ||
| highest_score_word_list.clear() | ||
| for word in words: | ||
| highest_score_word_list.append(word) | ||
| current_highest_score = score | ||
|
|
||
| shortest_word_length = 10 | ||
| shortest_word_list = [] | ||
| if len(highest_score_word_list) == 1: | ||
| final_tuple = (highest_score_word_list[0], current_highest_score) | ||
| return final_tuple | ||
| elif len(highest_score_word_list) > 1: | ||
| for word in highest_score_word_list: | ||
| if len(word) == 10: | ||
| return (word, current_highest_score) | ||
| else: | ||
| if len(word) < shortest_word_length: | ||
| shortest_word_list.append(word) | ||
| shortest_word_length=len(word) | ||
|
|
||
| return (shortest_word_list[-1], current_highest_score) |
There was a problem hiding this comment.
I saw that you took an approach using tuples. Here is a way to use tuples and shorten some of the lines of code:
| highest_score_word_list = [] | |
| comparing_word_scores = {} | |
| current_word_score = 0 | |
| for word in word_list: | |
| current_word_score = score_word(word) | |
| if comparing_word_scores.get(current_word_score): | |
| comparing_word_scores[current_word_score].append(word) | |
| else: | |
| comparing_word_scores[current_word_score] = [] | |
| comparing_word_scores[current_word_score].append(word) | |
| current_highest_score=0 | |
| for score, words in comparing_word_scores.items(): | |
| if score > current_highest_score: | |
| highest_score_word_list.clear() | |
| for word in words: | |
| highest_score_word_list.append(word) | |
| current_highest_score = score | |
| shortest_word_length = 10 | |
| shortest_word_list = [] | |
| if len(highest_score_word_list) == 1: | |
| final_tuple = (highest_score_word_list[0], current_highest_score) | |
| return final_tuple | |
| elif len(highest_score_word_list) > 1: | |
| for word in highest_score_word_list: | |
| if len(word) == 10: | |
| return (word, current_highest_score) | |
| else: | |
| if len(word) < shortest_word_length: | |
| shortest_word_list.append(word) | |
| shortest_word_length=len(word) | |
| return (shortest_word_list[-1], current_highest_score) | |
| highest = (word_list[0],0) | |
| for word in word_list: | |
| score = score_word(word) | |
| if score > highest[1]: | |
| highest = (word, score) | |
| elif score == highest[1]: | |
| if len(highest[0]) == 10: | |
| pass | |
| elif len(word) == 10 and len(highest[0]) != 10: | |
| highest = (word, score) | |
| elif len(word) < len(highest[0]): | |
| highest = (word, score) | |
| return highest |
|
Great work! I loved how you all set up your data structures. I added a few suggestions about using helpful methods, refactoring, and using global variables. |
No description provided.