Created
July 18, 2020 21:02
-
-
Save raeq/44d5ff2e97039c293b3a28490e7afa18 to your computer and use it in GitHub Desktop.
String similarity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import difflib | |
def similarity(left: str = "", right: str = "") -> float: | |
seq = difflib.SequenceMatcher(None, left, right) | |
return seq.ratio() | |
assert similarity("I like bananas", "I like bananarama") >= 0.80 | |
assert similarity("I like bananas", "The quick brown fox") <= 0.25 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment