Python Program to Check Two Strings are Equal

Aim:

Write a function nearly_equal to test whether two strings are nearly equal. Two strings a and b are nearly equal when a can be generated by a single mutation on b.

Program:

from difflib import SequenceMatcher
def Nearly_Equal(a,b):
 return SequenceMatcher(None,a,b).ratio();
a="khit"
b="khitc"
c=Nearly_Equal(a,b)
if(c*100>80):
 print("Both Strings are similar")
 print("a is mutation on b") 
else:
 print("Both Strings are Different") 

Execution:

Both Strings are similar
a is mutation on b

Leave a Comment