learning python as I go for school work. Essentially, I need to find the longest repeated substring in a list of string as shown here. I have been reading through this article and have an understanding of what I should do.
so far my implementation is as follows:
def long_rptr_subString(testList):
longSubstring = ''
if len(testList) > 1 and len(testList[0]) > 0:
for i in range(len(testList[0])):
for j in range(len(testList[0])-i+1):
if j > len(longSubstring) and all(testList[0][i:i+j] in x for x in testList):
longSubstring = testList[0][i:i+j]
return longSubstring
now when I call my function with let's say ['slide', 'glidb', 'flidt', 'cridz', 'bidr']
I get the correct result of 'id'
as being my longest substring.
However, when I pass the list ['slide', 'glidb', 'flidt', 'cridz', 'bidr', 'balh', 'tejka', 'djakljskdl', 'blah', 'blah', 'blah']
I don't get any return results. I should be getting back 'blah'
as my longest substring, but I haven't figured out a way to accomplish this. It seems I am only able to match substrings when they are in ALL items of the list. How might I modify my code/logic to get the longest substring that occurs more than once?
Thank you.