Skip to content
← Back to Community
5.7. Strings: Remove fragment
Profile icon
pole55

"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."

Voters
Profile icon
AddisonLeonard
Profile icon
ZhalgasAbdugali
Profile icon
BharanidharanR
Profile icon
YawJnrJnr
Profile icon
AndrewForrester
Profile icon
KiraMakarova
Profile icon
welcometochilis
Profile icon
rumaysa1
Profile icon
GiannaRicci
Profile icon
CollinHornsby
Comments
hotnewtop
Profile icon
AmirElangouri

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