-
Notifications
You must be signed in to change notification settings - Fork 2.2k
PCC02 LaneHesser #784
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
PCC02 LaneHesser #784
Conversation
LaneHesser
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Realized I had left out some functionality when I pushed the first time, so I made the changes and pushed again.
bbelderbos
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, some feedback
| def draw_letters(): | ||
| """Returns 7 random letters from POUCH""" | ||
| return [ | ||
| random.choice(POUCH) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can pick multiple random items at once: random.sample(POUCH, NUM_LETTERS)
|
|
||
| try: | ||
| if word not in DICTIONARY: | ||
| raise ValueError(f'{word} is not in the dictionary. Try again.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems you just print upon catching this ValueError so it's probably shorter to just to do this:
if DICTIONARY.get(word) is None:
print('error')
continue
| def get_user_input(draw): | ||
| """Asks the player to form a word with one or more letters from draw.""" | ||
| draw_copy = draw.copy() | ||
| print('Letters drawn:', *draw_copy) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f-string?
|
|
||
| def calc_optimal_word(draw): | ||
| """Calculates optimal word (highest value) given the letters in draw""" | ||
| permutations = _permutations(draw) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would call this differently, it clashes with itertools.permutations
| valid_words = set( | ||
| ''.join(word).lower() | ||
| for word in permutations | ||
| if ''.join(word).lower() in DICTIONARY |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wonder if you can do the lower() in _permutations to not do it twice here?
Difficulty level (1-10): [4]
Estimated time spent (hours): [4]
Completed (yes/no): [Yes]
I stretched my coding skills (if yes what did you learn?): [I learned some useful functions from the itertools module and how to put a few of them together to generate all permutations of the items in a sequence.]
Other feedback (what can we improve?): []