1# credit to the Stack Overflow user in the source link
2
3from difflib import SequenceMatcher
4
5string1 = "apple pie available"
6string2 = "come have some apple pies"
7
8match = SequenceMatcher(None, string1, string2).find_longest_match(0, len(string1), 0, len(string2))
9
10print(match) # -> Match(a=0, b=15, size=9)
11print(string1[match.a: match.a + match.size]) # -> apple pie
12print(string2[match.b: match.b + match.size]) # -> apple pie