What is an Anagram?
An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
Examples
act = cat
elbow = below
night = thing
a gentleman = elegant man
eleven plus two = twelve plus one
listen = silent
the detectives = detect thieves
History of Anagrams
Some historians have suggested, that anagrams originated in the 4th century B.C., but weren’t commonly used until the 13th century A.D. and even then, they were sometimes thought of as mystical.
Background Idea
Anagrams are fun linguistic phenomena to observe, but yet, one wonders if computers can be made to detect them too...
This thought brings to light the concept that, while computers are indeed fast, they still do not possess any human-like quality of intelligence, as we are all too familiar with, and as such would definitely need to be instructed to see patterns that exist in human language.
Due to the peculiarities of this task, a program would be written to give specific procedural instructions, on computational tasks to carry out.
To begin, one needs to understand that two (2) popular paradigms of coding exist:
...and, I have chosen to solve this task, using procedural code (AI helps via Natural Language Processing models but that’s another story)
Process
Step 1 - Clean the text
The snippet above represents the steps involved in cleaning the string representation of the words in question. One should always expect that text contain spaces and punctuation, hence the steps above outline the process involved in removing them, thereby allowing the algorithm to deal with the useful characters only.
Step 2 - Logic Algorithm
1) Using the "Counter" class from the built-in collections module
Python Anagram Detector - 1
2) Using the built-in "sorted" function
Python Anagram Detector - 2
Conclusion
Now that you understand the backend of an anagram detecting algorithm, you can then go on to build on it. That is, by adding more sophisticated features which would help detect anagrams from a whole text file (.txt) or better still deploy such solutions to the Web where users can solve their Anagram problems.
A more advanced solution to detecting anagrams would be, using Artificial Intelligence to detect them in text, this would certainly be an interesting concept, and useful applications would be found in quizzes, and word games (scrabble, etc.).
Check out linked tweet
1/3 🧵 Beginner’s Coding Project
— Regressor (@Wilder_Maxim) February 12, 2022
Building an algorithmic Python Anagram Detector (P.A.D.)
What is an Anagram?
An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.#Python #AI #NLP pic.twitter.com/fFSjuqNwxW
Let's Connect
Project Portfolio | GitHub | Kaggle | Tableau |