There is a built in.
from difflib import SequenceMatcher
def similar(a, b):
return SequenceMatcher(None, a, b).ratio()
Using it:
>>> similar("Apple","Appel")
0.8
>>> similar("Apple","Mango")
0.0
More Related Contents:
- Calculate cosine similarity given 2 sentence strings
- Python – Is a dictionary slow to find frequency of each character?
- What’s the fastest way in Python to calculate cosine similarity given sparse matrix data?
- How to incrementally sample without replacement?
- How do I simulate flip of biased coin?
- String similarity with Python + Sqlite (Levenshtein distance / edit distance)
- Selecting close matches from one array based on another reference array
- Normalizing a list of numbers in Python
- How to compute jaccard similarity from a pandas dataframe
- Converting between datetime, Timestamp and datetime64
- Class method decorator with self arguments?
- Reducing size of pyinstaller exe
- How do I split a string into a list of characters?
- Replace column values based on another dataframe python pandas – better way?
- How to remove duplicates from a csv file
- Get formula from Excel cell with python xlrd
- Is it possible only to declare a variable without assigning any value in Python?
- Python recursive function error: “maximum recursion depth exceeded” [duplicate]
- ctypes – Beginner
- What user do python scripts run as in windows? [duplicate]
- Printing to screen and writing to a file at the same time
- Python read csv – BOM embedded into the first key
- Why doesn’t calling a string method (such as .replace) modify (mutate) the string? Why doesn’t it change unless I assign the result?
- How do I check if a string represents a number (float or int)?
- What is more ‘pythonic’ for ‘not’ [duplicate]
- How to assign a new class attribute via __dict__?
- Proper way to parse requirements file after pip upgrade to pip 10.x.x?
- Python function returns None, unclear why [duplicate]
- improving python code in Monte Carlo simulation
- Lexical cast from string to type