-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from siddharth7000/patch-2
Create Python1.py
- Loading branch information
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from itertools import permutations | ||
|
||
def find_anagrams(word): | ||
# Generate all possible permutations of the letters in the word | ||
all_permutations = [''.join(perm) for perm in permutations(word)] | ||
|
||
# Filter permutations to find valid words using a dictionary (you may need a word list file) | ||
with open('wordlist.txt', 'r') as wordlist_file: | ||
wordlist = set(word.strip().lower() for word in wordlist_file) | ||
|
||
anagrams = [perm for perm in all_permutations if perm in wordlist] | ||
|
||
return anagrams | ||
|
||
if __name__ == "__main__": | ||
input_word = input("Enter a word: ").lower() | ||
anagrams = find_anagrams(input_word) | ||
|
||
if anagrams: | ||
print(f"Anagrams of '{input_word}':") | ||
for anagram in anagrams: | ||
print(anagram) | ||
else: | ||
print(f"No valid anagrams found for '{input_word}'.") |