Text Diff

import difflib
str1 = "I understand how customers do their choice. Difference"
str2 = "I understand how customers do their choice."
seq = difflib.SequenceMatcher(None, str1, str2)
d = seq.ratio()*100
d
88.65979381443299
def get_similarity(str1, str2):
    seq = difflib.SequenceMatcher(None, str1, str2)
    d = seq.ratio()*100
    return d
get_similarity(str1, str2)
88.65979381443299
get_similarity("Toronto is nice", "Toronto is looking nice")
78.94736842105263