Skip to content

Instantly share code, notes, and snippets.

@eirenik0
Last active December 17, 2015 23:58
Show Gist options
  • Save eirenik0/5692893 to your computer and use it in GitHub Desktop.
Save eirenik0/5692893 to your computer and use it in GitHub Desktop.
Finding the maximum of a string
#-*-coding: utf-8-*-
K = 3
STRINGS = ['abacainstitutebac', 'mycabacrchinstituteve', 'acabacinstinstituterue']
def sort(i, outputs=[]):
string = ""
k = i
while len(string) < len(STRINGS[0])-i:
string += "".join(list(STRINGS[0])[k])
for n in range(1, K):
if STRINGS[n].find(string) != -1 and n<K-1:
if STRINGS[n+1].find(string) != -1:
if string not in outputs:
outputs.append(string)
k += 1
return outputs
for i in range(len(STRINGS[0])):
found = sort(i)
i += 1
print max(found, key=len)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment