I am trying to use SequenceMatcher.ratio()
to get the similarity of two strings: "86418648"
and "86488648"
:
>>> SequenceMatcher(None,"86418648","86488648").ratio()
0.5
The ratio returned is 0.5
, which is much lower than I expected because there is only one character different in the two strings.
It seems that the ratio is calculated based on matching blocks. So I tried to run SequenceMatcher.get_matching_blocks()
:
>>> SequenceMatcher(None,"86418648","86488648").get_matching_blocks()
[Match(a=4, b=0, size=4), Match(a=8, b=8, size=0)]
But I expected the result to be:
[Match(a=0, b=0, size=3), Match(a=4, b=4, size=4), Match(a=8, b=8, size=0)]
Can anyone help to explain why it didn't match from the first 3 numbers "864"
?