How to find a close match of words / strings by python
This article mainly introduces python how to find words / strings of similar matching, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
Find a close match of a word / string
Now, about some obscure features in the Python standard library. If you find that you need to use something like Levenshtein distance [2] to find similar words in the input string, then Python's difflib will support you.
Import difflib difflib.get_close_matches ('appel', [' ape', 'apple',' peach', 'puppy'], nasty 2) # returns [' apple', 'ape']
Difflib.get_close_matches will look for the best "good enough" match. In this case, the first parameter matches the second parameter. We can also provide an optional parameter n, which specifies the maximum number of matching results to be returned. Another optional keyword parameter, cutoff (default is 0. 6), allows you to set a threshold for string matching scores.
Thank you for reading this article carefully. I hope the article "how to find a close match of words / strings" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and follow the industry information channel. More related knowledge is waiting for you to learn!