-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrabs.py
50 lines (39 loc) · 1.17 KB
/
scrabs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 11 14:05:50 2017
@author: nhowlett
"""
from data import *
# %% function for loading word list
def load_word_dictionary(filename):
with open(filename) as f:
words = f.readlines()
# Stripping newline characers
words = [x.strip().upper() for x in words]
return words
# %% function for calculating word value
def calc_word_value(word):
word = word.upper()
value = 0
for c in word:
value += LETTER_SCORES[c]
return value
# %% function for calculating word values for each word in list
def calc_list_values(words):
wordVals = []
for word in words:
wordVals.append((word, calc_word_value(word)))
return wordVals
# %% function for checking if word is contstructable from group of letters
def isWordValid(word, letters):
letters_test = [x.lower() for x in letters]
check = len(word)
for idx in range(check):
letter = word[idx]
if letter in letters_test:
letters_test.remove(letter)
check -= 1
if(check == 0):
return True
else:
return False