import re def subStrings(s, z): length = len(s) for size in range (length, 0, -1): startIdx = 0 endIdx = startIdx + size while (endIdx <= length): if (len(s[startIdx:endIdx]) > 1) and re.search(s[startIdx:endIdx], z): com = (s[startIdx:endIdx]) + "\n" lengthCom = len(s[startIdx:endIdx]) for size in range (lengthCom, 0, -1): startIdx = startIdx + 1 endIdx = startIdx + size while (endIdx <= length): if lengthCom == len(s[startIdx:endIdx]) and re.search(s[startIdx:endIdx], z): com = com + '{:^20}'.format(s[startIdx:endIdx]) + "\n" startIdx = startIdx + 1 endIdx = startIdx + size return com startIdx = startIdx + 1 endIdx = startIdx + size return 'No Common Sequence Found' def main(): inFile = open ("testCases2.txt", "r") x = int(inFile.readline()) for n in range(1, 2 * x + 1): globals()['dna' + str(n)] = inFile.readline() inFile.close() for n in range(1, 2 * x + 1): eval('dna' + str(n)).upper() print("Longest Common Sequences") print() for i in range(1, x + 1): print('Pair ' + str(i) + ": " + subStrings(eval('dna' + str(2 * i)), eval('dna' + str(2 * i - 1)))) main()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question