-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
55 lines (44 loc) · 1.44 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
53
54
55
import enchant
from itertools import permutations
language = enchant.Dict("en_US")
def get_permutation(letter_list, length=None):
permutation = permutations(letter_list, length)
words = permutation_processor(permutation)
display_words(words)
def permutation_processor(permutation):
for i in permutation:
joined_word = "".join(i)
word = check_words(joined_word)
yield word
def check_words(word):
if language.check(word):
return word
def get_letters():
beautiful_letters = input("Gimme those letters without space. Press return when finished. \n")
trimmed_beautiful_letters = beautiful_letters.strip()
splitted_letters = list(trimmed_beautiful_letters)
return splitted_letters
def get_size(splitted_letters):
beautiful_size = input("What length of word do you need? (Optional) \n")
if beautiful_size:
try:
beautiful_size = int(beautiful_size)
except ValueError:
print("Not a valid number 😟")
else:
beautiful_size = len(splitted_letters)
return beautiful_size
def display_words(words):
counter = 0
for word in words:
if word:
counter +=1
print(word)
if counter == 0:
print("Oops! No words found. You just broke the English language 😟")
def main():
letters = get_letters()
size = get_size(letters)
get_permutation(letters, size)
if __name__ == "__main__":
main()