Issue
I need to know whether we can compare 2 string of different length and check the substring is occured in given sring or not
For example:
str1='abcdef '
str2='acbcdef'
here length are same but letter is different how can i assign score for this
Solution
Use difflib
:
from difflib import SequenceMatcher
def similar(a, b):
return SequenceMatcher(None, a, b).ratio()
str1='abcdef '
str2='acbcdef'
print(similar(str1,str2))
Output:
0.8571428571428571
Answered By - U12-Forward
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.