-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercise_9_word_play.py
49 lines (35 loc) · 1.29 KB
/
exercise_9_word_play.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
from binary_search import make_word_list
def uses_all(word, required_letters):
return uses_only(required_letters, word)
def uses_only(word, given_letters):
for letter in word:
if letter not in given_letters:
return False
return True
def is_abecedarian(word):
new_w = sorted(list(word))
return ''.join(new_w) == word
word_list = make_word_list()
"""
# Get filter letters, word list from words.txt
letters = input("Enter letters which words should contain without spaces: ")
# Get the letters containing required letters at least once
list_uses_all = []
for words in word_list:
if uses_all(words, letters):
list_uses_all.append(words)
print("Word list contains {} words with letters '{}' ".format(len(list_uses_all), letters))
# Get the words containing given letters only
list_uses_only = []
for words in word_list:
if uses_only(words, letters):
list_uses_only.append(words)
print("Word list contains {} words with letters '{}' only".format(len(list_uses_only), letters))
print("List of words is: {}".format(list_uses_only))
# Get the list of words which are abecedarian
list_abecedarians = []
for words in word_list:
if is_abecedarian(words):
list_abecedarians.append(words)
print(list_abecedarians, len(list_abecedarians))
"""