Answer to Question #167079 in Python for hemanth

Question #167079

Prefix Suffix


Write a program to check the overlapping of one string's suffix with the prefix of another string.


Input


The first line of the input will contain a string A.

The second line of the input will contain a string B.


Output


The output should contain overlapping word if present else print "No overlapping".


Explanation


For example, if the given two strings, A and B, are "ramisgood" "goodforall"

The output should be "good" as good overlaps as a suffix of the first string and prefix of next.




1
Expert's answer
2021-02-26T12:08:38-0500
#!/usr/bin/python
import re

#implementatio using loop + slicing + startswith()

def overlapping(l,k):
    for char in range(len(str_A)):

 
        if str_B.startswith(str_A[char:]):
            res = str_A[char:]
            print("\nString A:", str_A)
            print("String B:", str_B)
            print("\nOverlapping String: " + str(res))
            break
    else:
        print("\nString A:", str_A)
        print("String B:", str_B)
        print ("\nNo overlapping")




print ("Input string A:")
str_A = str(input())

print("\nInput string B:")
str_B = str(input())

overlapping(str_A, str_B)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS