Skip to content

Instantly share code, notes, and snippets.

@colobas
Created August 31, 2018 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colobas/0b470c9adb25f64fc3c016608b537b54 to your computer and use it in GitHub Desktop.
Save colobas/0b470c9adb25f64fc3c016608b537b54 to your computer and use it in GitHub Desktop.
from difflib import SequenceMatcher
def longestSubstring(str1,str2):
# initialize SequenceMatcher object with
# input string
seqMatch = SequenceMatcher(None,str1,str2)
# find match of longest sub-string
# output will be like Match(a=0, b=0, size=5)
match = seqMatch.find_longest_match(0, len(str1), 0, len(str2))
# print longest substring
if (match.size!=0):
print (str1[match.a: match.a + match.size])
else:
print ('No longest common sub-string found')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment