-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
52 lines (37 loc) · 1.3 KB
/
main.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
import wget
import os
filename = './dictionaries/en/en_US.dic'
if not os.path.isfile(filename):
url = 'https://github.com/LibreOffice/dictionaries/raw/master/en/en_US.dic'
filename = wget.download(url)
def match_letters(letters_to_match, word):
# The word must have the same or fewer characters than the letters_to_match
if len(word) > len(letters_to_match):
return False
sorted_c_to_match = sorted(letters_to_match)
for c in sorted(list(word)):
if c in sorted_c_to_match:
sorted_c_to_match.remove(c)
else:
return False
return True
def main():
letters_to_match = input("Letters :")
with open(filename, 'r') as f:
lines = f.readlines()
line_count = len(lines)
print(f"Line_count: {line_count}")
for word_flag in lines:
word_flag_strip = word_flag.strip()
if '/' in word_flag_strip:
word = word_flag_strip.split('/')[0]
else:
word = word_flag_strip
# This is the invers
if (not word.isalpha()) or (not word.islower()) or (len(word) < 3):
continue
if not match_letters(letters_to_match, word):
continue
print(word)
if __name__ == "__main__":
main()