Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
simpledict solution in Clear category for DNA Common Sequence by DiZ
from collections import defaultdict
def common(first, second):
subsets = defaultdict(lambda:{''})
for i, a in enumerate(first):
for j, b in enumerate(second):
if a == b:
subsets[i, j] = {sub + a for sub in subsets[i - 1, j - 1]}
else:
s = subsets[i - 1, j] | subsets[i, j - 1]
subsets[i, j] = {sub for sub in s if len(sub) == max(map(len, s))}
return ','.join(sorted(subsets[max(subsets)]))
March 2, 2015
Comments: