Comparing 2 similar strings?

Irmen de Jong irmen.NOSPAM at xs4all.nl
Sat May 28 17:50:09 EDT 2005


Rob W. W. Hooft wrote:
> After reading this thread, I have wrapped up a different approach, 
> probably not what you were looking for, but it is very good for what I 
> wanted: comparing a command string typed by a user with all possible 
> commands a program can accept, to be able to do typo-correction. The 
> method will return a floating point number between 0.0 (no match) and 
> len(s)+1.0 (if the strings are exactly equal). You can see the score as 
> "the number of equal letters".
[...]
Interesting, but the result is a bit puzzling.
Wouldn't it be easier if it is normalized to a float between 0.0 and 1.0?

Furthermore, I can also produce wrong(?) results:

$ python comparestrings.py
s1: test
s2: x
Score: -0.4

Minus 0.4... Is this a bug?

--Irmen



More information about the Python-list mailing list