I have two strings, for example 'bbb', and 'bbab', and I want to find all of the overlaps between them (which in this case would be 'bbbbab', 'bbbab', and 'bbabbb'). Is there a python program in the documentation that does this?
Asked
Active
Viewed 3,092 times
1 Answers
3
There is no such library function, but you can do it like this:
def overlaps1( a, b ):
for i in range( 1, min( len(a), len(b) ) ):
if a[-i:] == b[:i]:
print( a + b[i:] )
def overlaps2( a, b ):
overlaps1(a,b)
overlaps1(b,a)
overlaps2( 'bbb', 'bbab' )

pentadecagon
- 4,717
- 2
- 18
- 26
-
1Probably should be `for i in range( 1, min( len(a), len(b) )+1 ):` – den2042 Nov 06 '14 at 16:18