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".
# overlapping of a prefix first_str with a suffix second_str
first_str = input('Enter the first string ')
second_str = input('Enter the second string ')
over_lapping =''
# get the length of the smallest word
min_len = min(len(first_str), len(second_str))
for item in range(min_len):
# comparison of a prefix first_str with a suffix second_str
if first_str[:item + 1] == second_str[-item -1:]:
over_lapping = first_str[:item + 1]
print(over_lapping) if over_lapping else print('No overlapping')
Comments
Leave a comment