def substring_between_letters(word, start, end):
strt = word.find(start)
endd = word.find(end)
if strt or endd == -1:
return word
else:
return word[strt+1:endd]
print(substring_between_letters("apple", "p", "e"))
print(substring_between_letters("apple", "p", "c"))
In both scenarios I am returning apple.
strt finds the index position of start endd finds the index position of end and if either of these are -1 then return the word else return what is between the letters
Aucun commentaire:
Enregistrer un commentaire