1
Between the word fogo
and the word gelo
there is a content, and the goal is to change that content by sobrenatural
code:
s = "1 fogo bom dia gelo 2 fogo boa tarde gelo 3 fogo boa noite gelo 4"
s = s.replace('\n\n','\t')
start = 'fogo'
end = 'gelo'
for i in range(len(s)): #1 fogo sobrenatural gelo 2 fogo sobrenatural gelo 3 fogo sobrenatural gelo 4
if s[i:i+len(start)] == start:
for j in range(i+len(start), len(s)):
if s[j:j+len(end)] == end:
g = s[i + len(start):j]
v=s.replace(g,' sobrenatural ')
print(v)
break
The print as it goes:
1 fogo sobrenatural gelo 2 fogo boa tarde gelo 3 fogo boa noite gelo 4
1 fogo bom dia gelo 2 fogo sobrenatural gelo 3 fogo boa noite gelo 4
1 fogo bom dia gelo 2 fogo boa tarde gelo 3 fogo sobrenatural gelo 4
The correct print would be:
1 fogo sobrenatural gelo 2 fogo sobrenatural gelo 3 fogo sobrenatural gelo 4
I would just add the
\b
to avoid cases like "Botafogo etc gelol", "fires etc froze", etc - it was not clear if it is to treat these cases, but anyway...– hkotsubo