Does anyone know why these two return different ratios.
>>> import difflib
>>> difflib.SequenceMatcher(None, '10101789', '11426089').ratio()
0.5
>>> difflib.SequenceMatcher(None, '11426089', '10101789').ratio()
0.625
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This gives some ideas of how matching works.
It looks as if it matches as much as it can on the first sequence against the second and continues from the matches. In this case (‘01017’, ‘14260’), the righthand match is on the 0, the last character, so no further matches on the right are possible. In this case (‘14260’, ‘01017’), the 1s match and the 0 still is available to match on the right, so two matches are found.
I think the matching algorithm is commutative against sorted sequences.