"Reverse the fragment: Given a string in which the letter h occurs at least two times, reverse the sequence of characters enclosed between the first and last appearances. " - Snakify python coding question

 



 

CODING QUESTION

Given a string in which the letter h occurs at least two times, reverse the sequence of characters enclosed between the first and last appearances.


SOLUTION

s=str(input())
print(s[:s.find('h')+1],s[s.rfind('h')-1:s.find('h'):-1],s[s.rfind('h'):],sep='')
#In the hole in the ground there lived a hobbit

 

Input : In the hole in the ground there lived a hobbit

Output : In th a devil ereht dnuorg eht ni eloh ehobbit