Given the words, the task is to extract different words from a set of characters using the defined dictionary.
Python in its language defines an inbuilt module
enchant which handles certain operations related to words. In the approach mentioned, following methods are used.
check() :It checks if a string is a word or not and returns true if a string is a word, else returns false.
permutations(str_arr, str_len) :It provides the combination of a string as per the mentioned string length.
There is a chance that
enchant() module might not be present, so it can be installed using pip3 install enchant.
Below is the Python code implementation of the above approach.
star is an English words tars is an English words arts is an English words rats is an English words perm_word [‘star’, ‘tars’, ‘arts’, ‘rats’] sat is an English word tar is an English word art is an English word rat is an English word perm_word [‘star’, ‘tars’, ‘arts’, ‘rats’, ‘sat’, ‘tar’, ‘art’, ‘rat’] st is an English word ts is an English word tr is an English word as is an English word at is an English word rs is an English word rt is an English word perm_word [‘star’, ‘tars’, ‘arts’, ‘rats’, ‘sat’, ‘tar’, ‘art’, ‘rat’, ‘st’, ‘ts’, ‘tr’, ‘as’, ‘at’, ‘rs’, ‘rt’]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course