Created
August 31, 2018 10:45
-
-
Save colobas/0b470c9adb25f64fc3c016608b537b54 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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