Comparing 2 similar strings?
Aahz
aahz at pythoncraft.com
Wed May 18 17:20:24 EDT 2005
[trimmed to c.l.py]
In article <24a6d$428b9c10$d1b717f8$2300 at PRIMUS.CA>,
William Park <opengeometry at yahoo.ca> wrote:
>
>How do you compare 2 strings, and determine how much they are "close" to
>each other? Eg.
> aqwerty
> qwertyb
>are similar to each other, except for first/last char. But, how do I
>quantify that?
>
>I guess you can say for the above 2 strings that
> - at max, 6 chars out of 7 are same sequence --> 85% max
>
>But, for
> qawerty
> qwerbty
>max correlation is
> - 3 chars out of 7 are the same sequence --> 42% max
difflib -- use the string as the sequence
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"And if that makes me an elitist...I couldn't be happier." --JMS
More information about the Python-list
mailing list