[issue45180] possible wrong result for difflib.SequenceMatcher.ratio()

2021-09-15 Thread Tim Peters
Tim Peters added the comment: Please stop re-opening this. The issue tracker is not a "help desk", and your confusions aren't necessarily Python bugs ;-) If you post something that looks like an actual bug, I'll re-open the report. SequenceMatcher works on sequences. HtmlFiff works on seque

[issue45180] possible wrong result for difflib.SequenceMatcher.ratio()

2021-09-15 Thread Nabeel Alzahrani
Nabeel Alzahrani added the comment: Here are the steps that I used to calculate 0.2 for the last example: I used class difflib.HtmlDiff to find the number of changed chars (addedChars, deletedChars, and changedChars) which is 1172 (let us call it delta) The size of both strings a and b in th

[issue45180] possible wrong result for difflib.SequenceMatcher.ratio()

2021-09-15 Thread Tim Peters
Tim Peters added the comment: I have no idea why you think the result should be 0.2. 0.5630188679245283 looks correct to me with autojunk disabled: sm = SequenceMatcher(None, a, b, autojunk=False) total = 0 for m in sm.get_matching_blocks(): print(m, repr(a[m.a : m.a + m.size]))

[issue45180] possible wrong result for difflib.SequenceMatcher.ratio()

2021-09-15 Thread Nabeel Alzahrani
Change by Nabeel Alzahrani : -- resolution: not a bug -> status: closed -> open ___ Python tracker ___ ___ Python-bugs-list mailing

[issue45180] possible wrong result for difflib.SequenceMatcher.ratio()

2021-09-15 Thread Nabeel Alzahrani
Nabeel Alzahrani added the comment: But when I turn off the "autojunk" feature for the following example, I get the wrong ratio of 0.5 instead of the correct ratio of 0.2 with autojunk enabled. a=""" #include #include using namespace std; int main() { string userPass; int sMaxInde

[issue45180] possible wrong result for difflib.SequenceMatcher.ratio()

2021-09-12 Thread Tim Peters
Tim Peters added the comment: Unfortunately, you're getting hurt by the "autojunk" feature (see the docs). If you turn it off, you'll get a result much more to your liking: >>> print(SequenceMatcher(None, a, b).ratio()) 0.3431803896920176 >>> print(SequenceMatcher(None, a, b, autojunk=False)

[issue45180] possible wrong result for difflib.SequenceMatcher.ratio()

2021-09-12 Thread Nabeel Alzahrani
New submission from Nabeel Alzahrani : The difflib.SequenceMatcher.ratio() gives 0.3 instead of 1.0 or at least 0.9 for the following two strings a and b: a=""" #include #include using namespace std; int main() { string userWord; unsigned int i; cin >> userWord; for