PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Put the two strings in separated lines :)
s1 = input()
s2 = input()
def find_all(string, sub):
n = 0
while True:
n = string.find(sub, n)
if n == -1: return
yield n
n += len(sub)
# find_all("Hello World!", "l") -> [2, 3, 9] # Generator
# My function is a recursive function, substracting first value of the first string every time.
def stringsStuff(string1, string2):
# Base cases
if len(string1) == 0: # No more analysis
return True
if not string1[0] in string2: # Obvious case ^_^
return False
for k in find_all(string2, string1[0]):
try:
secondValue = string1[1] # Last letter of the word
except IndexError:
return True # Analysis completed
try:
if string2[k-1] == secondValue: # Backward
return stringsStuff(string1[1:], string2) or False
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run