def get_indices_from_the_second_string(string1, string2):
\'\'\'(str, str) -> list of int
>>> get_indices_from_the_second_string(\'AGTACACGTTAC\', \'
Remove lines
i += 1
r += 1
as for
loops increase i
and r
automatically.
And then modify your code:
lower = 0 # from this index will be string1 searched
for i in range(0, len(string2)):
for r in range(lower, len(string1)):
if string1[r] == string2[i]:
acc.append(r)
lower = r + 1 # indexes from 0 to r are already used
break
elif r == len(string1) - 1: # last index did not match
return acc
return acc