letters = {'a': 1,'b': 3,'c': 3,'d': 2,'e': 1,'f': 4,'g': 2,'h': 4,'i': 1,'j': 8,'k': 5,'l': 1,'m': 3,'n': 1,'o': 1,'p': 3,'q': 10,'r': 1,'s': 1,'t': 1,'u': 1, 'v': 4,'w': 4,'x': 8,'y': 4,'z': 10,} hand = {'e': 1,'d': 1,'g': 1,'c': 1,'r': 1,'a': 1,'l': 1} matches = list() word_dict = dict() with open(file=r'C:\Users\YOUR_PATH\words.txt', mode='r') as f: words = [word.strip('\n') for word in f.readlines()] for word in words: for letter in word: if word_dict.get(letter): word_dict[letter] += 1 else: word_dict[letter] = 1 if word_dict.items() <= hand.items(): matches.append(word) word_dict = dict() match_dict = dict() for match in matches: word_points = 0 for letter in match: word_points += letters.get(letter) match_dict[match] = word_points match_dict = sorted(match_dict.items(), key=lambda item: item[1], reverse=True) print(match_dict)