Last active
December 17, 2015 23:58
-
-
Save eirenik0/5692893 to your computer and use it in GitHub Desktop.
Finding the maximum of a string
This file contains hidden or 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
#-*-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