I assume that you want the substrings to match if they have the same absolute position in their respective strings. For example, "abcd" and "bcde" will not match, although both contain "bcd".
a = "address"
b = "oddness"
matches = map(lambda x: x[0] == x[1], zip(list(a), list(b)))
positions = filter(lambda x: matches[x], range(len(a)))
substrings = filter(lambda x: x.find("_") == -1 and x != "","".join(map(lambda x: ["_", a[x]][matches[x]], range(len(a)))).split("_"))
position = [1, 2, 4, 5, 6]
substrings = ['dd', 'ess']
If you only need substrings, you can grind it into one line:
filter(lambda x: x.find("_") == -1 and x != "","".join(map(lambda x: ["_", a[x]][map(lambda x: x[0] == x[1], zip(list(a), list(b)))[x]], range(len(a)))).split("_"))
Kevin source
share