Share your repls and programming experiences

← Back to all posts
5.7. Strings: Remove fragment
pole55 (204)

"Given a string in which the letter h occurs at least twice. Remove from that string the first and the last occurrence of the letter h, as well as all the characters between them."

Commentshotnewtop
AmirElangouri (10)

Mine code is realy bad:
s = input()
if s.find('h') == 0:
print((s[s.rfind('h') + 1:]))
else:
print(str(s[0:s.find('h') - 1]) + str(s[s.find('h') - 1])+str(s[s.rfind('h') + 1:]))

i was looking for other people their solution why do i make everyting so complicated