Reputation: 155
The Levensthein distance provides a number which is the total number of differences between two strings. My question is: is it possible to retrieve, instead of the number, what are these differences? For example
a = "MyTest"
b = "MynewTest"
The Levensthein will be 3, but how do I retrieve and store the string "new"
?
I might combine the ndiff
library but is there an already available function?
Upvotes: 1
Views: 113
Reputation: 71610
Try this:
import difflib
print(''.join([i[-1] for i in difflib.ndiff("MyTest", "MynewTest") if i[0] == '+']))
Output:
new
Upvotes: 1