Skip to content

Conversation

@LaneHesser
Copy link

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?): []

Copy link
Author

@LaneHesser LaneHesser left a 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.

Copy link
Collaborator

@bbelderbos bbelderbos 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, some feedback

def draw_letters():
"""Returns 7 random letters from POUCH"""
return [
random.choice(POUCH)
Copy link
Collaborator

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.')
Copy link
Collaborator

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)
Copy link
Collaborator

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)
Copy link
Collaborator

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
Copy link
Collaborator

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?

@bbelderbos bbelderbos merged commit ec9e566 into pybites:community Dec 15, 2020
@LaneHesser
Copy link
Author

LaneHesser commented Dec 15, 2020 via email

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.

2 participants