Sorry, your browser is not supported
To have the best experience using Skillshare, we recommend that you use one of these supported browsers.

134

--

# Scrabble practice

For some reason Codecademy doesn't see the sowpods file. This ran right on my laptop though

scores = {"A": 1, "C": 4, "B": 4, "E": 1, "D": 2, "G": 3,
"F": 4, "I": 1, "H": 3, "K": 5, "J": 10, "M": 4,
"L": 2, "O": 1, "N": 2, "Q": 10, "P": 4, "S": 1,
"R": 1, "U": 2, "T": 1, "W": 4, "V": 4, "Y": 3,
"X": 8, "Z": 10}
# Turn the words in the sowpods.txt file into a Python list.
f = open("sowpods.txt", "r")

words_list = []

for line in f:
line = line.strip()
words_list.append(line)

f.close()
#print(len(words_list))

# Get the Scrabble rack from the command line

valid_words = []
import sys
rack = sys.argv[0]
rack= rack.upper()

print(rack)

# Find all valid words in sowpods
for word in words_list:
candidate = True
rack_letters = list(rack)
for letter in word:
if letter not in rack_letters:
candidate = False
else:
rack_letters.remove(letter)
if candidate == True:
total = 0
for letter in word:
total = total + scores[letter]
valid_words.append([total, word])

valid_words.sort()

for entry in valid_words:
score = entry[0]
word = entry[1]
print str(score) + " " + word