Skip to content

Commit

Permalink
Merge pull request #2 from siddharth7000/patch-2
Browse files Browse the repository at this point in the history
Create Python1.py
  • Loading branch information
Sidd7000 authored Oct 19, 2023
2 parents 99a0b75 + e05c17a commit 0c76049
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Python1.py
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}'.")

0 comments on commit 0c76049

Please sign in to comment.