8000 [039] Simply check_word with set comprehension · stephen-codepython/100DaysOfCode@98c4189 · GitHub
[go: up one dir, main page]

Skip to content

Commit 98c4189

Browse files
authored
[039] Simply check_word with set comprehension
1 parent e52079d commit 98c4189

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

039/word_checker.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,8 @@ def load_dictionary():
1212
return words
1313

1414
def check_word(dictionary, word):
15-
valid_words = set()
16-
permutations = []
17-
perms = list(itertools.permutations(word))
18-
for i in perms:
19-
permutations.append(''.join(i))
20-
21-
for i in permutations:
22-
if i in dictionary:
23-
valid_words.add(i)
24-
return valid_words
15+
permutations = set(map(''.join, itertools.permutations(word)))
16+
return {w for w in permutations if w in dictionary}
2517

2618
def print_words(words):
2719
for i in words:

0 commit comments

Comments
 (0)
0