Given an input of scrambled word, and I have a file of English words. I want to find all possible words that can be formed from the scrambled word.
from itertools import permutations
def unscramble(scrambled_word):
length=len(scrambled_word)
unscrambled_word=[]
for r in range(length):
if r >= 2:
permutation_object=permutations(scrambled_word, r)
unscrambled_list=[''.join(permutation) for permutation in permutation_object]
unscrambled_word.extend(unscrambled_list)
return unscrambled_word
def english_words():
with open("english_words.txt") as file_object:
content=file_object.read()
return content
unscrambled_word=unscramble("nidswow")
english_words=english_words()
for word in unscrambled_word:
if word in english_words:
print(word)