Input: patterns = ['ape',' apple', 'peach',' puppy'], input = 'appel' Output: [' apple', 'ape']
We can quickly solve this problem in python using the built-in difflib.get_close_matches () function.
difflib.get_close_matches (word, features, n, clipping) takes four parameters where n, clipping are optional. word — this is a sequence for which a close match is desired, possibilities — it is a list of sequences to which the word is matched. Optional argument n (default 3) — this is the maximum number of close matches to return, n must be greater than 0. Optional argument cutoff (default 0.6) — it is a floating point number in the range [0, 1]. Opportunities that are not rated, at least as a word, are ignored.
The best (no more than n) matches among the possibilities are returned in a list sorted by similarity score, most similar first.
# Function to find all close matches
# input string in the given list of possible strings
closeMatches (patterns, word): p>
(get_close_matches (word, patterns))
# Driver program
" __main__ "
closeMatches (patterns, word)
We are witnessing a movement that will completely transform any part of business and society. The word we have given to this move- ment is Big Data and it will change everything, from the way banks an...
Computer languages have so far been of the ‘interpreted’ or the ‘compiled’ type. Compiled languages (like ‘C’) have been more common. You prepare a program, save it (the debugged version),...
A Problem-Solver’s Guide to Building Real-World Intelligent Systems. Data is the new oil and Machine Learning is a powerful concept and framework for making the best out of it. In this age of aut...
Acquire and analyze data from all corners of the social web with Python. This book is for intermediate Python developers who want to engage with the use of public APIs to collect data from social m...