0

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?

Thomas
  • 123
  • 1
  • 6

1 Answers1

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