python - How to use SequenceMatcher to find similarity between two strings? -


import difflib  a='abcd' b='ab123' seq=difflib.sequencematcher(a=a.lower(),b=b.lower()) seq=difflib.sequencematcher(a,b) d=seq.ratio()*100 print d 

i used above code obtained output 0.0. how can valid answer?

you forgot first parameter sequencematcher.

>>> import difflib >>>  >>> a='abcd' >>> b='ab123' >>> seq=difflib.sequencematcher(none, a,b) >>> d=seq.ratio()*100 >>> print d 44.4444444444 

http://docs.python.org/library/difflib.html


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -