Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
# AdaGrams

## Plan of Action
Copy link

Choose a reason for hiding this comment

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

Excellent documentation of the plan!


# Access needs
Work on project during the hours of 9am-5pm-ish
If you receive a message and don’t have time to reply because it’s late, just let your partner know you will reply the next day

# Your learning style
Trial and error
Learn by doing
Both of us have similar learning styles as outlined above

# How you prefer to receive feedback
Detailed feedback is nice
Really honest feedback

# One team communication skill you want to improve with this experience
Giving and receiving non-sugar coated feedback
Be able to talk about code well; using correct software terms
Timely responses, communicating often and efficiently

# Other Communication:
If it’s past 4-5 hours, it’s fine to double-ping
If it’s late, just reply saying you saw the message and will reply the next day
Will attend most co-working sessions outlined in the calendar
Try to keep a work schedule (9-5) to allow for breaks/positive work-life balance


## Skills Assessed

- Following directions and reading comprehension
Expand Down
106 changes: 102 additions & 4 deletions adagrams/game.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,109 @@
import random

LETTER_DISTRIBUTION = {
"A": 9,
"B": 2,
"C": 2,
"D": 4,
"E": 12,
"F": 2,
"G": 3,
"H": 2,
"I": 9,
"J": 1,
"K": 1,
"L": 4,
"M": 2,
"N": 6,
"O": 8,
"P": 2,
"Q": 1,
"R": 6,
"S": 4,
"T": 6,
"U": 4,
"V": 2,
"W": 2,
"X": 1,
"Y": 2,
"Z": 1
}

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"]
}

def draw_letters():
pass
letter_pool = []
letter_bank = []
for letter, count in LETTER_DISTRIBUTION.items():
Copy link

Choose a reason for hiding this comment

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

This works perfectly well! I have a couple of suggestions - you don't really need to turn the LETTER_DISTRIBUTION dictionary in to a list of tuples in order to access the count nor do you need to use a for-loop with an unused variable i. Here's an alternative based on your approach which doesn't convert the dictionary to a list of tuples or create unused variables:

    for letter in LETTER_DISTRIBUTION:
        count = LETTER_DISTRIBUTION[letter]
        while count > 0:
            letter_pool.append(letter)
            count -= 1

for i in range(count):
letter_pool.append(letter)
# Should we rewrite 45-47 with list comprehension? This is what we tried:
# letter_pool = [[letter] * count
Copy link

Choose a reason for hiding this comment

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

If you want to write a list comprehension using the nested loop approach, you'd need a nested list comprehension. I speak for myself in saying I don't usually find those to be very readable.

# for letter, count in LETTER_DISTRIBUTION.items()]
for letter in range(10):
random_letter = random.choice(letter_pool)
letter_bank.append(random_letter)
letter_pool.remove(random_letter)
return letter_bank

def uses_available_letters(word, letter_bank):
pass
bank_dict = {}
# We tried to implement dictionary comprehension for this,
# but are unsure if it's possible:
# alt_bank_dict = {letter, 1 for letter in letter_bank
Copy link

Choose a reason for hiding this comment

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

It's possible! Try this:

    bank_dict = {letter: letter_bank.count(letter) for letter in letter_bank}

# if item not in alt_bank_dict else letter, + 1}
for item in letter_bank:
if item not in bank_dict:
bank_dict[item] = 1
else:
bank_dict[item] += 1
for letter in word.upper():
if letter not in bank_dict.keys():
Copy link

Choose a reason for hiding this comment

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

Python can iterate over a dictionary and uses its keys to do so, so no need to convert the dictionary to a list of dictionary keys just for iterating over it.

return False
elif letter in bank_dict.keys():
Copy link

Choose a reason for hiding this comment

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

Same as above, no need to convert to a list first.

bank_dict[letter] -= 1

if bank_dict[letter] < 0:
return False
return True

def score_word(word):
pass
total_score = 0
for character in word.upper():
Copy link

Choose a reason for hiding this comment

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

This does work however, if you create a data structure like:

{
    'A': 1, 
    'B': 3, 
    'C': 3, 
    'D': 2, 
...
}

Then you can avoid nested iteration:

    for letter in word:
        score_total += LETTER_VALUES[letter]

Which is much simpler and easier to read! Always consider the best data structure that allows the simplest and most straightforward access.

for tally, letters in SCORE_CHART.items():
if character in letters:
total_score += tally
if len(word) >= 7:
Copy link

Choose a reason for hiding this comment

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

👍 nice

total_score += 8
return total_score

def get_highest_word_score(word_list):
pass
word_info = [{"word": word, "score": score_word(word), "length": len(word)}
Copy link

Choose a reason for hiding this comment

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

This function works great! One minor improvement would be to avoid looping by checking whether there's only one element in word_info. Since that list only contains more than one element if there's ties, you can use that fact to return the sole element, e.g.

    if len(word_info) == 1:
        return word_info[0]["word"], word_info[0]["score"]

Then go on to do all the tie-break looping only if you actually have a tie.

for word in word_list]

highest_score = max(word_info, key=lambda word_info: word_info["score"])

word_info = list(filter(lambda word_dict: word_dict["score"]
== highest_score["score"], word_info))
# We also came up with this implementation for lines 94-95:
# for word_dict in word_info:
# if word_dict["score"] != highest_score["score"]:
# word_info.remove(word_dict)

smallest_length = min(word_info, key=lambda word_info: word_info["length"])

for word_dict in word_info:
if word_dict["length"] == 10:
return word_dict["word"], word_dict["score"]

for word_dict in word_info:
if word_dict["length"] == smallest_length["length"]:
return word_dict["word"], word_dict["score"]