Skip to content

Maple - Christine & Juliana #36

Open
Jruiz9312 wants to merge 4 commits intoAda-C16:masterfrom
Jruiz9312:master
Open

Maple - Christine & Juliana #36
Jruiz9312 wants to merge 4 commits intoAda-C16:masterfrom
Jruiz9312:master

Conversation

@Jruiz9312
Copy link
Copy Markdown

No description provided.

Comment thread adagrams/game.py

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"]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I would suggest making this a global constant variable to remove "clutter" from your function

Comment thread adagrams/game.py
Comment on lines +7 to +11
main_letters_list_copy = []
user_hand = []

for letter in main_letters_list:
main_letters_list_copy.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.

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

Comment thread adagrams/game.py
Comment on lines +24 to +26
letter_bank_copy = []
for letter in letter_bank:
letter_bank_copy.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.

same suggestion about using copy() method. Even though this works great!

Comment thread adagrams/game.py
Comment on lines +38 to +46
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"]
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

loved how you set up the key-value pairs. I would suggest making this a global constant variable.

Comment thread adagrams/game.py
Comment on lines +62 to +95
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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I saw that you took an approach using tuples. Here is a way to use tuples and shorten some of the lines of code:

Suggested change
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

@tgoslee
Copy link
Copy Markdown

tgoslee commented Oct 5, 2021

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.

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