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

Nabeel Alzahrani report at bugs.python.org
Wed Sep 15 22:03:59 EDT 2021


Nabeel Alzahrani <nalza001 at ucr.edu> 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 <iostream>
#include <string>
using namespace std;
int main() {
   
   string userPass;
   int sMaxIndex;
   char indivChar;
   int i;
   
   cin >> userPass;
   
   sMaxIndex = userPass.size() - 1;
   
   
   for (i = 0; i <= sMaxIndex; ++i) {
      
      indivChar = userPass.at(i);
      
      if (indivChar == 'i') {
         
         indivChar = '1';
         cout << indivChar;
         
      }
      else if (indivChar == 'a') {
         
         indivChar = '@';
         cout << indivChar;
         
      }
      else if (indivChar == 'm') {
         
         indivChar = 'M';
         cout << indivChar;
         
      }
      else if (indivChar == 'B') {
         
         indivChar = '8';
         cout << indivChar;
         
      }
      else if (indivChar == 's') {
         
         indivChar = '$';
         cout << indivChar;
         
      }
      else {
         
         cout << indivChar;
         
      }
      
   }
   
   cout << "!" << endl;
   
   return 0;
}
"""

b="""
#include <iostream>
#include <string>
using namespace std;
int main() {
   string ori;
   cin >> ori;
   for (int i = 0; i < ori.size(); i++){
      if (ori.at(i) == 'i')
         ori.at(i) = '1';
      if (ori.at(i) == 'a')
         ori.at(i) = '@';
      if (ori.at(i) == 'm')
         ori.at(i) = 'M';
      if (ori.at(i) == 'B')
         ori.at(i) = '8';
      if (ori.at(i) == 's')
         ori.at(i) = '$';
      }
   cout << ori << endl;

   return 0;
}
"""

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45180>
_______________________________________


More information about the Python-bugs-list mailing list