-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathletterhack.py
executable file
·59 lines (55 loc) · 1.88 KB
/
letterhack.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
51
52
53
54
55
56
57
58
59
#!/usr/bin/python
from copy import copy
import sys
def find_words(letter_string, preferred_letters=''):
#Convert letters to lowercase and split it into a list
letters = list(letter_string.lower())
preferred = list(preferred_letters.lower())
#list to hold our words loaded from our text file
words=[]
found_words=[]
preferred_words=[]
partial_words=[]
#load words from dictionary file
with open("enable.txt") as f:
words = [line.strip() for line in f.readlines()]
#for each word in the list
for word in words:
word_as_list = list(word)
pref = copy(preferred)
any_missing = False
for letter in letters:
if letter in word_as_list:
word_as_list.remove(letter)
if letter in pref:
pref.remove(letter)
else:
any_missing = True
if len(word_as_list) == 0:
found_words.append(word)
if preferred and len(pref) == 0:
preferred_words.append(word)
if not any_missing:
partial_words.append(word)
found_words.sort(key=len)
preferred_words.sort(key=len)
partial_words.sort(key=len)
print "Top 5 Words by length: "
for word in found_words[-5:]:
print word
if preferred_letters:
print "Top 5 preferred Words by length: "
for word in preferred_words[-5:]:
print word
print "Top 5 Words by that are supersets: "
for word in partial_words[:10]:
print word
if __name__ == '__main__':
#The list of letters that appear on your letterpress screen
letter_string = 'WCVOUBISHROZORELDANCLZYVG'
preferred_letters = ''
if len(sys.argv) > 1:
letter_string = sys.argv[1]
if len(sys.argv) > 2:
preferred_letters = sys.argv[2]
find_words(letter_string, preferred_letters)