Explore

Close
Python Programs Share

Making An Python Anagram Solver With Code

Python Anagram Solver

Today in this python tutorial I will show you how to make a python anagram solver. If you are looking to build an anagram solver in python programming then this is the only guide you need to follow.

An anagram is a word that is rephrased or rearranged to form another word, for example anagram of arc is car, dam is mad, etc. Another good example is “I’m a dot in place” will become “A decimal point”.

I hope you got what is an anagram so we want to build an anagram solver in python programming which will ask the user to enter a word that they want anagrams of then it will provide a list of suitable anagrams words.

After reading this full article you will get a python anagram solver with code that will solve anagram puzzles so read till the end

Making An Python Anagram Solver

Making an anagram solver in python looks complicated and difficult by the way but we will use some python libraries which will help us solve anagram in python with just a few lines of code.

So before we go further if you don’t have python installed on your computer then you need to first download and install it on your computer for this you can refer to this guide: Installing and setting up python.

Install pyenchant library

This is the python library which we will use, It is a spell checking library it suggests correct words when miss-spelled so you need to install this library so to install this library use the below command


pip install pyenchant

After you install the library you need the code so create a python file and copy and paste the below code for python anagram solver.

Anagram Solver Python Code



from itertools import permutations,combinations
import enchant

d = enchant.Dict("en_US")
word = input('Enter word: ')
letters = [chr for chr in word]
repeat_check = []

for number in range(3,len(letters)+1): #For Loop
    for current_set in combinations(letters,number): #Combinations Function
        #Code for the Basic Anagram Finder
        for current in permutations(current_set):
            current_word = ''.join(current)
            if d.check(current_word)and current_word not in repeat_check:
                print(current_word)
                repeat_check.append(current_word)

As you can see the code is just around 15 lines so now you need to run this program you can use the below command to run a python file


python filename.py

If you have to run the command in the command prompt and enter the name of your python filename so after running below will be the output.

Output


Enter word: gainly
lying
inlay
gainly
laying

After running it will ask you to enter a word you want the anagram of. In my case I have entered “arc” . It gave me a “car” . It also can give many word suggestions according to the word you enter.

You can use this python anagram program to solve any anagram puzzle. So this was it. I hope you found this program useful and helpful. Now let’s see more about this program.

Summary

This was the python anagram solver program that solves anagram puzzles. This program looks very simple because libraries remove a lot of code complexities.

Want more python tutorials like this then here are some more guides you may find helpful:

I hope you found what you were looking for in this python tutorial. If you want more guides like this do join our Telegram channel to stay updated.

Thanks for reading, have a nice day 🙂