File tree Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Original file line number Diff line number Diff line change 4
4
anagrams.py - Given a word, returns a list of words of anagrams for it.
5
5
"""
6
6
7
+ from collections import Counter
8
+
7
9
EN_DICITONARY = 'ciphers/utils/en_dictionary.txt'
8
10
9
11
def main ():
@@ -17,17 +19,14 @@ def main():
17
19
print ('Anagrams found:' , * anagram_list , sep = '\n ' )
18
20
19
21
20
- def find_anagrams (list_of_words , word ):
21
- anagrams = []
22
- target = sorted (word .lower ())
23
- [anagrams .append (w ) for w in list_of_words if sorted (w .lower ()) == target ]
24
- return anagrams
22
+ def find_anagrams (list_of_words , target ):
23
+ return [w for w in list_of_words if Counter (w .lower ()) == Counter (target )]
25
24
26
25
27
26
def take_user_input (prompt_text ):
28
27
res = input (prompt_text )
29
- while len (res . strip (). split ()) != 1 :
30
- print ('You must type in a single word' )
28
+ while len (res ) == 0 :
29
+ print ('You must type at least one word' )
31
30
res = input (prompt_text )
32
31
return res
33
32
You can’t perform that action at this time.
0 commit comments